Skip to content

Commit

Permalink
Upgrade Coding Standard
Browse files Browse the repository at this point in the history
  • Loading branch information
natanfelles committed Sep 29, 2023
1 parent 820e7b0 commit 33f47e3
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -63,7 +63,7 @@
},
"require-dev": {
"ext-xdebug": "*",
"aplus/coding-standard": "^1.14",
"aplus/coding-standard": "^2.0",
"ergebnis/composer-normalize": "^2.28",
"jetbrains/phpstorm-attributes": "^1.0",
"phpmd/phpmd": "^2.13",
Expand Down
18 changes: 9 additions & 9 deletions src/App.php
Expand Up @@ -117,7 +117,7 @@ public function __construct(Config | array | string $config = null, bool $debug
if (isset(static::$config)) {
throw new LogicException('App already initialized');
}
if ( ! $config instanceof Config) {
if (!$config instanceof Config) {
$config = new Config($config);
}
static::$config = $config;
Expand Down Expand Up @@ -178,7 +178,7 @@ protected function loadExceptionHandler() : void
if ($config->getDir() !== null) {
$exceptionHandlerConfigs ??= $this->loadConfigs('exceptionHandler');
}
if ( ! isset($exceptionHandlerConfigs['default'])) {
if (!isset($exceptionHandlerConfigs['default'])) {
$environment = static::isDebugging()
? ExceptionHandler::DEVELOPMENT
: ExceptionHandler::PRODUCTION;
Expand Down Expand Up @@ -230,8 +230,8 @@ protected function debugEnd() : void
{
static::$debugCollector->setEndTime()->setEndMemory();
$response = static::router()->getResponse();
if ( ! $response->hasDownload()
&& ! $response->getRequest()->isAjax()
if (!$response->hasDownload()
&& !$response->getRequest()->isAjax()
&& \str_contains(
(string) $response->getHeader('Content-Type'),
'text/html'
Expand Down Expand Up @@ -492,7 +492,7 @@ protected static function addCommand(string $file, Console $console, Locator $lo
if ($className === null) {
return false;
}
if ( ! \class_exists($className)) {
if (!\class_exists($className)) {
Isolation::require($file);
}
$class = new ReflectionClass($className); // @phpstan-ignore-line
Expand Down Expand Up @@ -1033,7 +1033,7 @@ protected static function setRouter(string $instance, array $config = null) : Ro
if (isset($config['auto_methods']) && $config['auto_methods'] === true) {
$service->setAutoMethods();
}
if ( ! empty($config['placeholders'])) {
if (!empty($config['placeholders'])) {
$service->addPlaceholder($config['placeholders']);
}
if ($requireFiles && isset($config['files'])) {
Expand All @@ -1050,7 +1050,7 @@ protected static function setRouter(string $instance, array $config = null) : Ro
protected static function requireRouterFiles(array $files) : void
{
foreach ($files as $file) {
if ( ! \is_file($file)) {
if (!\is_file($file)) {
throw new LogicException('Invalid router file: ' . $file);
}
Isolation::require($file);
Expand Down Expand Up @@ -1158,10 +1158,10 @@ protected static function setResponse(string $instance) : Response
{
$config = static::config()->get('response', $instance);
$service = new Response(static::request($config['request_instance'] ?? 'default'));
if ( ! empty($config['headers'])) {
if (!empty($config['headers'])) {
$service->setHeaders($config['headers']);
}
if ( ! empty($config['auto_etag'])) {
if (!empty($config['auto_etag'])) {
$service->setAutoEtag(
$config['auto_etag']['active'] ?? true,
$config['auto_etag']['hash_algo'] ?? null
Expand Down
14 changes: 7 additions & 7 deletions src/Debug/AppCollector.php
Expand Up @@ -31,10 +31,10 @@ class AppCollector extends Collector
public function setApp(App $app) : static
{
$this->app = $app;
if ( ! isset($this->startTime)) {
if (!isset($this->startTime)) {
$this->setStartTime();
}
if ( ! isset($this->startMemory)) {
if (!isset($this->startMemory)) {
$this->setStartMemory();
}
return $this;
Expand Down Expand Up @@ -90,10 +90,10 @@ public function getActivities() : array

public function getContents() : string
{
if ( ! isset($this->endTime)) {
if (!isset($this->endTime)) {
$this->setEndTime(\microtime(true));
}
if ( ! isset($this->endMemory)) {
if (!isset($this->endMemory)) {
$this->setEndMemory(\memory_get_usage());
}
\ob_start(); ?>
Expand Down Expand Up @@ -161,7 +161,7 @@ protected function getServices() : array
{
$result = [];
foreach ($this->getData() as $data) {
if ( ! isset($result[$data['service']])) {
if (!isset($result[$data['service']])) {
$result[$data['service']] = [];
}
$result[$data['service']][] = [
Expand All @@ -180,7 +180,7 @@ protected function renderAvailableServices() : string
$class = new ReflectionClass($this->app);
$methods = $class->getMethods(ReflectionMethod::IS_STATIC);
foreach ($methods as $method) {
if ( ! $method->isPublic()) {
if (!$method->isPublic()) {
continue;
}
$name = $method->getName();
Expand All @@ -196,7 +196,7 @@ protected function renderAvailableServices() : string
continue;
}
$param = $method->getParameters()[0] ?? null;
if ( ! $param || $param->getName() !== 'instance') {
if (!$param || $param->getName() !== 'instance') {
continue;
}
if ($param->getType()?->getName() !== 'string') { // @phpstan-ignore-line
Expand Down
2 changes: 1 addition & 1 deletion src/Debug/ViewCollector.php
Expand Up @@ -73,7 +73,7 @@ public function getContents() : string

protected function renderRenderedViews() : string
{
if ( ! $this->hasData()) {
if (!$this->hasData()) {
return '<p>No view has been rendered.</p>';
}
$data = $this->getSortedData();
Expand Down
6 changes: 3 additions & 3 deletions src/Entity.php
Expand Up @@ -140,7 +140,7 @@ protected function populate(array $properties) : void

protected function setProperty(string $name, mixed $value) : void
{
if ( ! \property_exists($this, $name)) {
if (!\property_exists($this, $name)) {
throw $this->propertyNotDefined($name);
}
if ($value !== null) {
Expand Down Expand Up @@ -251,7 +251,7 @@ public function toModel() : array

public function jsonSerialize() : stdClass
{
if ( ! $this->getJsonVars()) {
if (!$this->getJsonVars()) {
return new stdClass();
}
$allowed = \array_flip($this->getJsonVars());
Expand All @@ -268,7 +268,7 @@ protected function getObjectVars() : array
{
$result = [];
foreach (\get_object_vars($this) as $key => $value) {
if ( ! \str_starts_with($key, '_')) {
if (!\str_starts_with($key, '_')) {
$result[$key] = $value;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Model.php
Expand Up @@ -825,7 +825,7 @@ public function getValidationMessages() : array
*/
protected function getValidationRules() : array
{
if ( ! isset($this->validationRules)) {
if (!isset($this->validationRules)) {
throw new RuntimeException('Validation rules are not set');
}
return $this->validationRules;
Expand Down
4 changes: 2 additions & 2 deletions src/Validator.php
Expand Up @@ -38,7 +38,7 @@ public static function notUnique(
int | string $ignoreValue = '',
string $connection = 'default'
) : bool {
return ! static::unique(
return !static::unique(
$field,
$data,
$tableColumn,
Expand Down Expand Up @@ -90,7 +90,7 @@ public static function unique(
->expressions(['count' => static fn () => 'COUNT(*)'])
->from($table)
->whereEqual($column, $value);
if ($ignoreColumn !== '' && ! \preg_match('#^{(\w+)}$#', $ignoreValue)) {
if ($ignoreColumn !== '' && !\preg_match('#^{(\w+)}$#', $ignoreValue)) {
$statement->whereNotEqual($ignoreColumn, $ignoreValue);
}
return $statement->limit(1)->run()->fetch()->count < 1; // @phpstan-ignore-line
Expand Down
10 changes: 5 additions & 5 deletions src/View.php
Expand Up @@ -66,7 +66,7 @@ public function __destruct()
public function setBaseDir(string $baseDir) : static
{
$real = \realpath($baseDir);
if ( ! $real || ! \is_dir($real)) {
if (!$real || !\is_dir($real)) {
throw new InvalidArgumentException("View base dir is not a valid directory: {$baseDir} ");
}
$this->baseDir = \rtrim($real, '\\/ ') . \DIRECTORY_SEPARATOR;
Expand Down Expand Up @@ -150,10 +150,10 @@ protected function getFilepath(string $view) : string
}
$view = $this->getBaseDir() . $view . $this->getExtension();
$real = \realpath($view);
if ( ! $real || ! \is_file($real)) {
if (!$real || !\is_file($real)) {
throw new InvalidArgumentException("View path does not match a file: {$view}");
}
if ($this->getBaseDir() && ! \str_starts_with($real, $this->getBaseDir())) {
if ($this->getBaseDir() && !\str_starts_with($real, $this->getBaseDir())) {
throw new InvalidArgumentException("View path out of base directory: {$real}");
}
return $real;
Expand Down Expand Up @@ -255,7 +255,7 @@ public function endBlock() : static
echo \PHP_EOL . '<!-- Block end: ' . $block . ' -->' . \PHP_EOL;
}
$contents = \ob_get_clean();
if ( ! isset($this->blocks[$name])) {
if (!isset($this->blocks[$name])) {
$this->blocks[$name] = $contents; // @phpstan-ignore-line
}
return $this;
Expand Down Expand Up @@ -367,7 +367,7 @@ protected function getContents(string $view, array $data) : string
$data['view'] = $this;
\ob_start();
Isolation::require($this->getFilepath($view), $data);
if (isset($this->openBlock) && ! $this->inInclude) {
if (isset($this->openBlock) && !$this->inInclude) {
$this->openBlock = null;
$this->endBlock();
}
Expand Down

0 comments on commit 33f47e3

Please sign in to comment.