Skip to content

Commit

Permalink
Added more php-cs-fixer rules
Browse files Browse the repository at this point in the history
  • Loading branch information
freost committed Nov 13, 2024
1 parent d06b96f commit 7fa77d9
Show file tree
Hide file tree
Showing 59 changed files with 127 additions and 114 deletions.
13 changes: 13 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,27 @@
'align_multiline_comment' => true,
'array_syntax' => ['syntax' => 'short'],
'assign_null_coalescing_to_coalesce_equal' => true,
'attribute_empty_parentheses' => true,
'backtick_to_shell_exec' => true,
'blank_line_after_namespace' => true,
'blank_line_after_opening_tag' => true,
'blank_lines_before_namespace' => ['min_line_breaks' => 2, 'max_line_breaks' => 2],
'braces_position' => true,
'cast_spaces' => true,
'class_reference_name_casing' => true,
'combine_consecutive_issets' => true,
'combine_consecutive_unsets' => true,
'combine_nested_dirname' => true,
'concat_space' => ['spacing' => 'one'],
'constant_case' => true,
'declare_equal_normalize' => true,
'declare_parentheses' => true,
'dir_constant' => true,
'elseif' => true,
'encoding' => true,
'explicit_indirect_variable' => true,
'full_opening_tag' => true,
'fully_qualified_strict_types' => true,
'function_declaration' => true,
'function_to_constant' => true,
'get_class_to_class_keyword' => true,
Expand All @@ -39,16 +47,20 @@
'native_function_casing' => true,
'native_type_declaration_casing' => true,
'no_alias_functions' => true,
'no_alias_language_construct_call' => true,
'no_blank_lines_after_phpdoc' => true,
'no_closing_tag' => true,
'no_empty_statement' => true,
'no_extra_blank_lines' => true,
'no_leading_import_slash' => true,
'no_leading_namespace_whitespace' => true,
'no_mixed_echo_print' => true,
'no_multiline_whitespace_around_double_arrow' => true,
'no_singleline_whitespace_before_semicolons' => true,
'no_trailing_comma_in_singleline' => true,
'no_trailing_whitespace_in_comment' => true,
'no_trailing_whitespace' => true,
'no_unneeded_control_parentheses' => true,
'no_unset_cast' => true,
'no_unused_imports' => true,
'no_useless_sprintf' => true,
Expand All @@ -57,6 +69,7 @@
'non_printable_character' => true,
'normalize_index_brace' => true,
'nullable_type_declaration_for_default_null_value' => true,
'nullable_type_declaration' => true,
'object_operator_without_whitespace' => true,
'octal_notation' => true,
'ordered_imports' => ['imports_order' => ['class', 'function', 'const']],
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"php": ">=8.3.0",
"ext-json": "*",
"ext-mbstring": "*",
"monolog/monolog": "^3.7",
"monolog/monolog": "^3.8",
"symfony/var-dumper": "^7.1",
"doctrine/sql-formatter": "^1.5",
"psr/log": "^2.0|^3.0"
Expand Down
2 changes: 1 addition & 1 deletion src/mako/application/CurrentApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class CurrentApplication
/**
* Current application instance.
*/
protected static null|Application $application = null;
protected static ?Application $application = null;

/**
* Constructor.
Expand Down
2 changes: 1 addition & 1 deletion src/mako/application/cli/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ protected function getApplicationCommands(): array
$attributes = $reflection->getAttributes(CommandName::class);

if (empty($attributes)) {
/** @var \mako\reactor\CommandInterface $command */
/** @var CommandInterface $command */
$command = $reflection->newInstanceWithoutConstructor();

$command = $command->getCommand();
Expand Down
4 changes: 2 additions & 2 deletions src/mako/application/cli/commands/app/ListRoutes.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function execute(Routes $routes, Dispatcher $dispatcher, Router $router,

$matched = 0;

/** @var \mako\http\routing\Route $route */
/** @var Route $route */
foreach ($routes->getRoutes() as $route) {
if ($filter !== null && !$this->routeMatches($filter, $route)) {
continue;
Expand All @@ -96,7 +96,7 @@ public function execute(Routes $routes, Dispatcher $dispatcher, Router $router,
$matched++;

$middleware = (function ($middleware) {
/** @var \mako\http\routing\Dispatcher $this */
/** @var Dispatcher $this */
return $this->orderMiddlewareByPriority($middleware);
})
->bindTo($dispatcher, Dispatcher::class)([
Expand Down
2 changes: 1 addition & 1 deletion src/mako/cache/stores/Memcache.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function putIfNotExists(string $key, mixed $data, int $ttl = 0): bool
*/
public function has(string $key): bool
{
return ($this->memcache->get($this->getPrefixedKey($key)) !== false);
return $this->memcache->get($this->getPrefixedKey($key)) !== false;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/mako/cache/stores/Memcached.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function decrement(string $key, int $step = 1): false|int
*/
public function has(string $key): bool
{
return ($this->memcached->get($this->getPrefixedKey($key)) !== false);
return $this->memcached->get($this->getPrefixedKey($key)) !== false;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/mako/cache/stores/Memory.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function decrement(string $key, int $step = 1): false|int
*/
public function has(string $key): bool
{
return (isset($this->cache[$key]) && $this->cache[$key]['ttl'] > time());
return isset($this->cache[$key]) && $this->cache[$key]['ttl'] > time();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/mako/cache/stores/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ abstract class Store implements StoreInterface
/**
* Prefix.
*/
protected null|string $prefix = null;
protected ?string $prefix = null;

/**
* Sets the cache key prefix.
Expand Down
4 changes: 2 additions & 2 deletions src/mako/classes/preload/PreloaderGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected function getTypeClasses(ReflectionType $type): array
}
}
elseif ($type instanceof ReflectionIntersectionType) {
/** @var \ReflectionNamedType $intersectionType */
/** @var ReflectionNamedType $intersectionType */
foreach ($type->getTypes() as $intersectionType) {
$class = $intersectionType->getName();

Expand All @@ -67,7 +67,7 @@ protected function getTypeClasses(ReflectionType $type): array
}
}
elseif ($type instanceof ReflectionUnionType) {
/** @var \ReflectionIntersectionType|\ReflectionNamedType $unionType */
/** @var ReflectionIntersectionType|ReflectionNamedType $unionType */
foreach ($type->getTypes() as $unionType) {
if ($unionType instanceof ReflectionIntersectionType) {
$classes = [...$classes, ...$this->getTypeClasses($unionType)];
Expand Down
4 changes: 2 additions & 2 deletions src/mako/cli/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ class Environment
/**
* Do we have ANSI support?
*/
protected null|bool $hasAnsiSupport = null;
protected ?bool $hasAnsiSupport = null;

/**
* Do we have stty support?
*/
protected null|bool $hasStty = null;
protected ?bool $hasStty = null;

/**
* Stty settings.
Expand Down
2 changes: 1 addition & 1 deletion src/mako/cli/input/arguments/Argument.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class Argument
/**
* Argument alias.
*/
protected null|string $alias = null;
protected ?string $alias = null;

/**
* Is the argument positional?
Expand Down
2 changes: 1 addition & 1 deletion src/mako/cli/output/components/Alert.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class Alert
/**
* Formatter.
*/
protected null|FormatterInterface $formatter = null;
protected ?FormatterInterface $formatter = null;

/**
* Constructor.
Expand Down
2 changes: 1 addition & 1 deletion src/mako/cli/output/components/OrderedList.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class OrderedList
/**
* Formatter instance.
*/
protected null|FormatterInterface $formatter = null;
protected ?FormatterInterface $formatter = null;

/**
* Constructor.
Expand Down
2 changes: 1 addition & 1 deletion src/mako/cli/output/components/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Table
/**
* Formatter.
*/
protected null|FormatterInterface $formatter = null;
protected ?FormatterInterface $formatter = null;

/**
* Constructor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ trait ProgressTrait
/**
* Time of last redraw.
*/
protected null|float $lastRedraw = null;
protected ?float $lastRedraw = null;

/**
* Progress status.
Expand Down
2 changes: 1 addition & 1 deletion src/mako/cli/output/writer/Writer.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ abstract class Writer implements WriterInterface
/**
* Is the stream direct?
*/
protected null|bool $isDirect = null;
protected ?bool $isDirect = null;

/**
* {@inheritDoc}
Expand Down
4 changes: 2 additions & 2 deletions src/mako/common/AdapterManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function extend(string $name, Closure|string $adapter): void
protected function factory(string $adapterName, array $configuration = []): mixed
{
if (method_exists($this, ($method = "{$adapterName}Factory"))) {
return $this->$method($configuration);
return $this->{$method}($configuration);
}
elseif (isset($this->extensions[$adapterName])) {
$adapter = $this->extensions[$adapterName];
Expand Down Expand Up @@ -95,6 +95,6 @@ public function getInstance(?string $configuration = null): mixed
*/
public function __call(string $name, array $arguments): mixed
{
return $this->getInstance()->$name(...$arguments);
return $this->getInstance()->{$name}(...$arguments);
}
}
2 changes: 1 addition & 1 deletion src/mako/common/ConnectionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,6 @@ public function removeConfiguration(string $name): void
*/
public function __call(string $name, array $arguments): mixed
{
return $this->getConnection()->$name(...$arguments);
return $this->getConnection()->{$name}(...$arguments);
}
}
8 changes: 4 additions & 4 deletions src/mako/database/connections/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ class Connection
/**
* Database username.
*/
protected null|string $username;
protected ?string $username;

/**
* Database password.
*/
protected null|string $password;
protected ?string $password;

/**
* Enable the query log?
Expand Down Expand Up @@ -88,7 +88,7 @@ class Connection
/**
* PDO object.
*/
protected null|PDO $pdo;
protected ?PDO $pdo;

/**
* Transaction nesting level.
Expand Down Expand Up @@ -369,7 +369,7 @@ protected function prepareQueryAndParams(string $query, array $params): array
*/
protected function isConnectionLostAndShouldItBeReestablished(): bool
{
return ($this->reconnect === true && $this->inTransaction() === false && $this->isAlive() === false);
return $this->reconnect === true && $this->inTransaction() === false && $this->isAlive() === false;
}

/**
Expand Down
14 changes: 7 additions & 7 deletions src/mako/database/midgard/ORM.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ abstract class ORM implements JsonSerializable, Stringable
/**
* Connection name to use for the model.
*/
protected null|string $connectionName = null;
protected ?string $connectionName = null;

/**
* Connection manager instance.
*/
protected static null|ConnectionManager $connectionManager = null;
protected static ?ConnectionManager $connectionManager = null;

/**
* ORM query builder hooks.
Expand Down Expand Up @@ -248,11 +248,11 @@ protected function registerHooksAndCasts(): void

foreach (ClassInspector::getTraits(static::class) as $trait) {
if (method_exists($this, $getter = "get{$this->getClassShortName($trait)}Hooks")) {
static::$traitHooks[static::class] = array_merge_recursive(static::$traitHooks[static::class], $this->$getter());
static::$traitHooks[static::class] = array_merge_recursive(static::$traitHooks[static::class], $this->{$getter}());
}

if (method_exists($this, $getter = "get{$this->getClassShortName($trait)}Casts")) {
static::$traitCasts[static::class] += $this->$getter();
static::$traitCasts[static::class] += $this->{$getter}();
}
}
}
Expand Down Expand Up @@ -506,7 +506,7 @@ public function getValue(string $name): mixed
elseif ($this->isRelation($name)) {
// The column is a relation. Lazy load the record(s) and cache them

return $this->related[$name] = $this->$name()->getRelated();
return $this->related[$name] = $this->{$name}()->getRelated();
}

// All options have been exhausted so we'll throw an exception
Expand Down Expand Up @@ -943,14 +943,14 @@ public function __toString(): string
*/
public function __call(string $name, array $arguments): mixed
{
return $this->getQuery()->$name(...$arguments);
return $this->getQuery()->{$name}(...$arguments);
}

/**
* Forwards static method calls to the query builder.
*/
public static function __callStatic(string $name, array $arguments): mixed
{
return (new static)->getQuery()->$name(...$arguments);
return (new static)->getQuery()->{$name}(...$arguments);
}
}
10 changes: 5 additions & 5 deletions src/mako/database/midgard/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public function update(array $values): int
public function increment(string $column, int $increment = 1): int
{
if ($this->model->isPersisted()) {
$this->model->$column += $increment;
$this->model->{$column} += $increment;

$this->where($this->model->getPrimaryKey(), '=', $this->model->getPrimaryKeyValue());
}
Expand All @@ -227,7 +227,7 @@ public function increment(string $column, int $increment = 1): int
public function decrement(string $column, int $decrement = 1): int
{
if ($this->model->isPersisted()) {
$this->model->$column -= $decrement;
$this->model->{$column} -= $decrement;

$this->where($this->model->getPrimaryKey(), '=', $this->model->getPrimaryKeyValue());
}
Expand Down Expand Up @@ -380,8 +380,8 @@ public function withCountOf(array|string $relations): static

[$relation, $alias] = $this->parseRelationCountName($relation);

/** @var \mako\database\midgard\relations\Relation $countQuery */
$countQuery = $this->model->$relation()->getRelationCountQuery()->inSubqueryContext();
/** @var relations\Relation $countQuery */
$countQuery = $this->model->{$relation}()->getRelationCountQuery()->inSubqueryContext();

if ($criteria !== null) {
$criteria($countQuery);
Expand Down Expand Up @@ -462,7 +462,7 @@ protected function loadIncludes(array $results): void

$forward = $includes['forward'][$methodName] ?? [];

$results[0]->$methodName()->eagerLoad($results, $propertyName, $criteria, $forward);
$results[0]->{$methodName}()->eagerLoad($results, $propertyName, $criteria, $forward);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/mako/database/midgard/relations/ManyToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public function eagerLoad(array &$results, string $relation, ?Closure $criteria,
foreach ($this->eagerLoadChunked($this->keys($results)) as $related) {
$grouped[$related->getRawColumnValue($foreignKey)][] = $related;

unset($related->$foreignKey); // Unset as it's not a part of the record
unset($related->{$foreignKey}); // Unset as it's not a part of the record
}

foreach ($results as $result) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function getValue(string $name): mixed
elseif ($this->isRelation($name)) {
// The column is a relation. Lazy load the record(s) and cache them

return $this->related[$name] = $this->$name()->getRelated();
return $this->related[$name] = $this->{$name}()->getRelated();
}

// All options have been exhausted so we'll throw an exception
Expand Down
Loading

0 comments on commit 7fa77d9

Please sign in to comment.