From 0c38916535d4bbb14caff220bc815f008e7e8c16 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 17 Aug 2021 18:14:12 +0700 Subject: [PATCH 1/2] [Rector] Apply Rector dead code set list --- composer.json | 2 +- rector.php | 60 ++++++++++++++----- system/Database/Forge.php | 20 +++---- system/Database/MySQLi/Result.php | 2 +- system/Database/SQLSRV/Connection.php | 6 +- system/Database/SQLSRV/Forge.php | 22 ++++--- system/Debug/Toolbar.php | 9 +-- system/Debug/Toolbar/Collectors/Files.php | 2 +- system/Events/Events.php | 4 +- system/Filters/Filters.php | 4 -- system/HTTP/URI.php | 3 - system/Helpers/html_helper.php | 18 ++---- system/Helpers/text_helper.php | 6 +- system/Log/Logger.php | 2 +- system/Pager/Pager.php | 2 - system/Pager/PagerRenderer.php | 6 +- system/Router/RouteCollectionInterface.php | 4 -- system/Router/Router.php | 6 -- system/Security/Security.php | 8 ++- system/Session/Session.php | 4 +- system/Test/Fabricator.php | 6 -- system/Test/Mock/MockBuilder.php | 5 -- system/Throttle/Throttler.php | 2 - system/Validation/Rules.php | 4 +- tests/system/API/ResponseTraitTest.php | 4 +- .../system/Cache/Handlers/FileHandlerTest.php | 2 +- tests/system/Cookie/CookieStoreTest.php | 2 +- tests/system/Database/Live/UpdateTest.php | 4 -- tests/system/Events/EventsTest.php | 2 +- tests/system/Pager/PagerTest.php | 10 ++-- tests/system/Session/SessionTest.php | 4 +- 31 files changed, 110 insertions(+), 125 deletions(-) diff --git a/composer.json b/composer.json index 224164546dc3..26fd890bf6bc 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "phpstan/phpstan": "^0.12.91", "phpunit/phpunit": "^9.1", "predis/predis": "^1.1", - "rector/rector": "0.11.47", + "rector/rector": "0.11.48", "symplify/package-builder": "^9.3" }, "suggest": { diff --git a/rector.php b/rector.php index 22e33e3d0730..7ed60ffb1382 100644 --- a/rector.php +++ b/rector.php @@ -27,13 +27,14 @@ use Rector\CodingStyle\Rector\FuncCall\CountArrayToEmptyArrayComparisonRector; use Rector\Core\Configuration\Option; use Rector\Core\ValueObject\PhpVersion; -use Rector\DeadCode\Rector\Array_\RemoveDuplicatedArrayKeyRector; -use Rector\DeadCode\Rector\Assign\RemoveDoubleAssignRector; -use Rector\DeadCode\Rector\Assign\RemoveUnusedVariableAssignRector; -use Rector\DeadCode\Rector\Concat\RemoveConcatAutocastRector; -use Rector\DeadCode\Rector\Foreach_\RemoveUnusedForeachKeyRector; -use Rector\DeadCode\Rector\Property\RemoveUnusedPrivatePropertyRector; -use Rector\DeadCode\Rector\Switch_\RemoveDuplicatedCaseInSwitchRector; +use Rector\DeadCode\Rector\Cast\RecastingRemovalRector; +use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector; +use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPromotedPropertyRector; +use Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector; +use Rector\DeadCode\Rector\Expression\RemoveDeadStmtRector; +use Rector\DeadCode\Rector\If_\UnwrapFutureCompatibleIfPhpVersionRector; +use Rector\DeadCode\Rector\MethodCall\RemoveEmptyMethodCallRector; +use Rector\DeadCode\Rector\StaticCall\RemoveParentCallWithoutParentRector; use Rector\EarlyReturn\Rector\Foreach_\ChangeNestedForeachIfsToEarlyContinueRector; use Rector\EarlyReturn\Rector\If_\ChangeIfElseValueAssignToEarlyReturnRector; use Rector\EarlyReturn\Rector\If_\RemoveAlwaysElseRector; @@ -51,6 +52,7 @@ use Utils\Rector\UnderscoreToCamelCaseVariableNameRector; return static function (ContainerConfigurator $containerConfigurator): void { + $containerConfigurator->import(SetList::DEAD_CODE); $containerConfigurator->import(SetList::PHP_73); $parameters = $containerConfigurator->parameters(); @@ -72,6 +74,43 @@ __DIR__ . '/tests/_support', JsonThrowOnErrorRector::class, StringifyStrNeedlesRector::class, + + // requires php 8 + RemoveUnusedPromotedPropertyRector::class, + + // currently buggy on call inside assign, wait for next release + RemoveParentCallWithoutParentRector::class, + + // private method called via getPrivateMethodInvoker + RemoveUnusedPrivateMethodRector::class => [ + __DIR__ . '/system/Entity/Entity.php', + __DIR__ . '/tests/system/Test/ReflectionHelperTest.php', + ], + + // call on purpose for nothing happen check + RemoveEmptyMethodCallRector::class => [ + __DIR__ . '/tests', + ], + + // currently buggy on class implements ArrayAccess, wait for next release + RemoveDeadStmtRector::class => [ + __DIR__ . '/tests/system/Cookie/CookieTest.php', + ], + + // check on constant compare + UnwrapFutureCompatibleIfPhpVersionRector::class => [ + __DIR__ . '/system/CodeIgniter.php', + ], + + // check context ResponseTrait + RemoveUselessReturnTagRector::class => [ + __DIR__ . '/system/HTTP/MessageTrait.php', + ], + + // casted to Entity via EntityTest->getCastEntity() + RecastingRemovalRector::class => [ + __DIR__ . '/tests/system/Entity/EntityTest.php', + ], ]); // auto import fully qualified class names @@ -92,17 +131,13 @@ $services->set(SimplifyStrposLowerRector::class); $services->set(CombineIfRector::class); $services->set(SimplifyIfReturnBoolRector::class); - $services->set(RemoveDuplicatedCaseInSwitchRector::class); $services->set(InlineIfToExplicitIfRector::class); $services->set(PreparedValueToEarlyReturnRector::class); $services->set(ShortenElseIfRector::class); - $services->set(RemoveUnusedForeachKeyRector::class); $services->set(SimplifyIfElseToTernaryRector::class); $services->set(UnusedForeachValueToArrayKeysRector::class); - $services->set(RemoveConcatAutocastRector::class); $services->set(ChangeArrayPushToArrayAssignRector::class); $services->set(UnnecessaryTernaryExpressionRector::class); - $services->set(RemoveUnusedPrivatePropertyRector::class); $services->set(RemoveErrorSuppressInTryCatchStmtsRector::class); $services->set(TernaryToNullCoalescingRector::class); $services->set(ListToArrayDestructRector::class); @@ -110,9 +145,6 @@ $services->set(AddPregQuoteDelimiterRector::class); $services->set(SimplifyRegexPatternRector::class); $services->set(RemoveExtraParametersRector::class); - $services->set(RemoveUnusedVariableAssignRector::class); $services->set(FuncGetArgsToVariadicParamRector::class); $services->set(MakeInheritedMethodVisibilitySameAsParentRector::class); - $services->set(RemoveDuplicatedArrayKeyRector::class); - $services->set(RemoveDoubleAssignRector::class); }; diff --git a/system/Database/Forge.php b/system/Database/Forge.php index 4e3048290d42..ba3423a890ea 100644 --- a/system/Database/Forge.php +++ b/system/Database/Forge.php @@ -996,20 +996,18 @@ protected function _processForeignKeys(string $table): string 'SET DEFAULT', ]; - if ($this->foreignKeys !== []) { - foreach ($this->foreignKeys as $field => $fkey) { - $nameIndex = $table . '_' . $field . '_foreign'; + foreach ($this->foreignKeys as $field => $fkey) { + $nameIndex = $table . '_' . $field . '_foreign'; - $sql .= ",\n\tCONSTRAINT " . $this->db->escapeIdentifiers($nameIndex) - . ' FOREIGN KEY(' . $this->db->escapeIdentifiers($field) . ') REFERENCES ' . $this->db->escapeIdentifiers($this->db->DBPrefix . $fkey['table']) . ' (' . $this->db->escapeIdentifiers($fkey['field']) . ')'; + $sql .= ",\n\tCONSTRAINT " . $this->db->escapeIdentifiers($nameIndex) + . ' FOREIGN KEY(' . $this->db->escapeIdentifiers($field) . ') REFERENCES ' . $this->db->escapeIdentifiers($this->db->DBPrefix . $fkey['table']) . ' (' . $this->db->escapeIdentifiers($fkey['field']) . ')'; - if ($fkey['onDelete'] !== false && in_array($fkey['onDelete'], $allowActions, true)) { - $sql .= ' ON DELETE ' . $fkey['onDelete']; - } + if ($fkey['onDelete'] !== false && in_array($fkey['onDelete'], $allowActions, true)) { + $sql .= ' ON DELETE ' . $fkey['onDelete']; + } - if ($fkey['onUpdate'] !== false && in_array($fkey['onUpdate'], $allowActions, true)) { - $sql .= ' ON UPDATE ' . $fkey['onUpdate']; - } + if ($fkey['onUpdate'] !== false && in_array($fkey['onUpdate'], $allowActions, true)) { + $sql .= ' ON UPDATE ' . $fkey['onUpdate']; } } diff --git a/system/Database/MySQLi/Result.php b/system/Database/MySQLi/Result.php index b115697e65b9..7eab7d86c685 100644 --- a/system/Database/MySQLi/Result.php +++ b/system/Database/MySQLi/Result.php @@ -89,7 +89,7 @@ public function getFieldData(): array $retVal[$i]->type = $data->type; $retVal[$i]->type_name = in_array($data->type, [1, 247], true) ? 'char' : ($dataTypes[$data->type] ?? null); $retVal[$i]->max_length = $data->max_length; - $retVal[$i]->primary_key = (int) ($data->flags & 2); + $retVal[$i]->primary_key = $data->flags & 2; $retVal[$i]->length = $data->length; $retVal[$i]->default = $data->def; } diff --git a/system/Database/SQLSRV/Connection.php b/system/Database/SQLSRV/Connection.php index 24aa409ed1de..f09a96d69213 100755 --- a/system/Database/SQLSRV/Connection.php +++ b/system/Database/SQLSRV/Connection.php @@ -354,7 +354,7 @@ protected function _fieldData(string $table): array */ protected function _transBegin(): bool { - return (bool) sqlsrv_begin_transaction($this->connID); + return sqlsrv_begin_transaction($this->connID); } /** @@ -362,7 +362,7 @@ protected function _transBegin(): bool */ protected function _transCommit(): bool { - return (bool) sqlsrv_commit($this->connID); + return sqlsrv_commit($this->connID); } /** @@ -370,7 +370,7 @@ protected function _transCommit(): bool */ protected function _transRollback(): bool { - return (bool) sqlsrv_rollback($this->connID); + return sqlsrv_rollback($this->connID); } /** diff --git a/system/Database/SQLSRV/Forge.php b/system/Database/SQLSRV/Forge.php index ab5c3f2d5316..43131698703f 100755 --- a/system/Database/SQLSRV/Forge.php +++ b/system/Database/SQLSRV/Forge.php @@ -224,21 +224,19 @@ protected function _processForeignKeys(string $table): string $allowActions = ['CASCADE', 'SET NULL', 'NO ACTION', 'RESTRICT', 'SET DEFAULT']; - if ($this->foreignKeys !== []) { - foreach ($this->foreignKeys as $field => $fkey) { - $nameIndex = $table . '_' . $field . '_foreign'; + foreach ($this->foreignKeys as $field => $fkey) { + $nameIndex = $table . '_' . $field . '_foreign'; - $sql .= ",\n\t CONSTRAINT " . $this->db->escapeIdentifiers($nameIndex) - . ' FOREIGN KEY (' . $this->db->escapeIdentifiers($field) . ') ' - . ' REFERENCES ' . $this->db->escapeIdentifiers($this->db->getPrefix() . $fkey['table']) . ' (' . $this->db->escapeIdentifiers($fkey['field']) . ')'; + $sql .= ",\n\t CONSTRAINT " . $this->db->escapeIdentifiers($nameIndex) + . ' FOREIGN KEY (' . $this->db->escapeIdentifiers($field) . ') ' + . ' REFERENCES ' . $this->db->escapeIdentifiers($this->db->getPrefix() . $fkey['table']) . ' (' . $this->db->escapeIdentifiers($fkey['field']) . ')'; - if ($fkey['onDelete'] !== false && in_array($fkey['onDelete'], $allowActions, true)) { - $sql .= ' ON DELETE ' . $fkey['onDelete']; - } + if ($fkey['onDelete'] !== false && in_array($fkey['onDelete'], $allowActions, true)) { + $sql .= ' ON DELETE ' . $fkey['onDelete']; + } - if ($fkey['onUpdate'] !== false && in_array($fkey['onUpdate'], $allowActions, true)) { - $sql .= ' ON UPDATE ' . $fkey['onUpdate']; - } + if ($fkey['onUpdate'] !== false && in_array($fkey['onUpdate'], $allowActions, true)) { + $sql .= ' ON UPDATE ' . $fkey['onUpdate']; } } diff --git a/system/Debug/Toolbar.php b/system/Debug/Toolbar.php index 6e6a0a8fc88f..16432054d2e2 100644 --- a/system/Debug/Toolbar.php +++ b/system/Debug/Toolbar.php @@ -66,17 +66,14 @@ public function __construct(ToolbarConfig $config) /** * Returns all the data required by Debug Bar * - * @param float $startTime App start time + * @param float $startTime App start time + * @param IncomingRequest $request + * @param Response $response * * @return string JSON encoded data */ public function run(float $startTime, float $totalTime, RequestInterface $request, ResponseInterface $response): string { - /** - * @var IncomingRequest $request - * @var Response $response - */ - // Data items used within the view. $data['url'] = current_url(); $data['method'] = $request->getMethod(true); diff --git a/system/Debug/Toolbar/Collectors/Files.php b/system/Debug/Toolbar/Collectors/Files.php index d476154db1c3..d6aefd2c3fe9 100644 --- a/system/Debug/Toolbar/Collectors/Files.php +++ b/system/Debug/Toolbar/Collectors/Files.php @@ -45,7 +45,7 @@ class Files extends BaseCollector */ public function getTitleDetails(): string { - return '( ' . (int) count(get_included_files()) . ' )'; + return '( ' . count(get_included_files()) . ' )'; } /** diff --git a/system/Events/Events.php b/system/Events/Events.php index a0d9c7616451..ac08107459ca 100644 --- a/system/Events/Events.php +++ b/system/Events/Events.php @@ -71,9 +71,7 @@ public static function initialize() return; } - /** - * @var Modules - */ + /** @var Modules $config */ $config = config('Modules'); $events = APPPATH . 'Config' . DIRECTORY_SEPARATOR . 'Events.php'; $files = []; diff --git a/system/Filters/Filters.php b/system/Filters/Filters.php index bce502a3f4e9..9e3a0aa7913d 100644 --- a/system/Filters/Filters.php +++ b/system/Filters/Filters.php @@ -254,8 +254,6 @@ public function initialize(?string $uri = null) * Restores instance to its pre-initialized state. * Most useful for testing so the service can be * re-initialized to a different path. - * - * @return $this */ public function reset(): self { @@ -427,8 +425,6 @@ protected function processMethods() if (array_key_exists($method, $this->config->methods)) { $this->filters['before'] = array_merge($this->filters['before'], $this->config->methods[$method]); - - return; } } diff --git a/system/HTTP/URI.php b/system/HTTP/URI.php index f6eec4e80a4a..c7bdbb135354 100644 --- a/system/HTTP/URI.php +++ b/system/HTTP/URI.php @@ -997,9 +997,6 @@ public function resolveRelativeURI(string $uri) * Section 5.2 * * @see http://tools.ietf.org/html/rfc3986#section-5.2.3 - * - * @param URI $base - * @param URI $reference */ protected function mergePaths(self $base, self $reference): string { diff --git a/system/Helpers/html_helper.php b/system/Helpers/html_helper.php index dc175afe4e93..a1a51af11955 100755 --- a/system/Helpers/html_helper.php +++ b/system/Helpers/html_helper.php @@ -304,10 +304,8 @@ function video($src, string $unsupportedMessage = '', string $attributes = '', a $video .= ">\n"; - if (! empty($tracks)) { - foreach ($tracks as $track) { - $video .= _space_indent() . $track . "\n"; - } + foreach ($tracks as $track) { + $video .= _space_indent() . $track . "\n"; } if (! empty($unsupportedMessage)) { @@ -352,10 +350,8 @@ function audio($src, string $unsupportedMessage = '', string $attributes = '', a $audio .= '>'; - if (! empty($tracks)) { - foreach ($tracks as $track) { - $audio .= "\n" . _space_indent() . $track; - } + foreach ($tracks as $track) { + $audio .= "\n" . _space_indent() . $track; } if (! empty($unsupportedMessage)) { @@ -388,10 +384,8 @@ function _media(string $name, array $types = [], string $unsupportedMessage = '' $media .= _space_indent() . $option . "\n"; } - if (! empty($tracks)) { - foreach ($tracks as $track) { - $media .= _space_indent() . $track . "\n"; - } + foreach ($tracks as $track) { + $media .= _space_indent() . $track . "\n"; } if (! empty($unsupportedMessage)) { diff --git a/system/Helpers/text_helper.php b/system/Helpers/text_helper.php index 23f674be9eb3..5f0738421908 100755 --- a/system/Helpers/text_helper.php +++ b/system/Helpers/text_helper.php @@ -395,10 +395,8 @@ function word_wrap(string $str, int $charlim = 76): string } // Put our markers back - if (! empty($unwrap)) { - foreach ($unwrap as $key => $val) { - $output = str_replace('{{unwrapped' . $key . '}}', $val, $output); - } + foreach ($unwrap as $key => $val) { + $output = str_replace('{{unwrapped' . $key . '}}', $val, $output); } // remove any trailing newline diff --git a/system/Log/Logger.php b/system/Log/Logger.php index cfceeb3f5449..cee971161f36 100644 --- a/system/Log/Logger.php +++ b/system/Log/Logger.php @@ -282,7 +282,7 @@ public function log($level, $message, array $context = []): bool } /** - * @var HandlerInterface + * @var HandlerInterface $handler */ $handler = $this->handlers[$className]; diff --git a/system/Pager/Pager.php b/system/Pager/Pager.php index a23f710f3c73..a653485633aa 100644 --- a/system/Pager/Pager.php +++ b/system/Pager/Pager.php @@ -363,8 +363,6 @@ public function getDetails(string $group = 'default'): array /** * Sets only allowed queries on pagination links. - * - * @return Pager */ public function only(array $queries): self { diff --git a/system/Pager/PagerRenderer.php b/system/Pager/PagerRenderer.php index e1f20a5492a6..8c70314dc99f 100644 --- a/system/Pager/PagerRenderer.php +++ b/system/Pager/PagerRenderer.php @@ -239,7 +239,7 @@ public function links(): array $uri = $this->segment === 0 ? $uri->addQuery($this->pageSelector, $i) : $uri->setSegment($this->segment, $i); $links[] = [ 'uri' => URI::createURIString($uri->getScheme(), $uri->getAuthority(), $uri->getPath(), $uri->getQuery(), $uri->getFragment()), - 'title' => (int) $i, + 'title' => $i, 'active' => ($i === $this->current), ]; } @@ -260,8 +260,8 @@ protected function updatePages(?int $count = null) return; } - $this->first = $this->current - $count > 0 ? (int) ($this->current - $count) : 1; - $this->last = $this->current + $count <= $this->pageCount ? (int) ($this->current + $count) : (int) $this->pageCount; + $this->first = $this->current - $count > 0 ? $this->current - $count : 1; + $this->last = $this->current + $count <= $this->pageCount ? $this->current + $count : (int) $this->pageCount; } /** diff --git a/system/Router/RouteCollectionInterface.php b/system/Router/RouteCollectionInterface.php index 2a376f61ef32..da25077da0fb 100644 --- a/system/Router/RouteCollectionInterface.php +++ b/system/Router/RouteCollectionInterface.php @@ -92,8 +92,6 @@ public function setTranslateURIDashes(bool $value); * defined routes. * * If FALSE, will stop searching and do NO automatic routing. - * - * @return RouteCollectionInterface */ public function setAutoRoute(bool $value): self; @@ -105,8 +103,6 @@ public function setAutoRoute(bool $value): self; * This setting is passed to the Router class and handled there. * * @param callable|null $callable - * - * @return RouteCollectionInterface */ public function set404Override($callable = null): self; diff --git a/system/Router/Router.php b/system/Router/Router.php index aa29abebc56a..a5ccef2c2e3b 100644 --- a/system/Router/Router.php +++ b/system/Router/Router.php @@ -268,8 +268,6 @@ public function getMatchedRouteOptions() * it a blank. * * @param string $page - * - * @return $this */ public function setIndexPage($page): self { @@ -281,10 +279,6 @@ public function setIndexPage($page): self /** * Tells the system whether we should translate URI dashes or not * in the URI from a dash to an underscore. - * - * @param bool|false $val - * - * @return $this */ public function setTranslateURIDashes(bool $val = false): self { diff --git a/system/Security/Security.php b/system/Security/Security.php index eca76b483fcb..59a24a0cbd0f 100644 --- a/system/Security/Security.php +++ b/system/Security/Security.php @@ -125,7 +125,9 @@ class Security implements SecurityInterface */ public function __construct(App $config) { - /** @var SecurityConfig */ + /** + * @var SecurityConfig $security + */ $security = config('Security'); // Store CSRF-related configurations @@ -134,7 +136,9 @@ public function __construct(App $config) $this->regenerate = $security->regenerate ?? $config->CSRFRegenerate ?? $this->regenerate; $rawCookieName = $security->cookieName ?? $config->CSRFCookieName ?? $this->cookieName; - /** @var CookieConfig */ + /** + * @var CookieConfig $cookie + */ $cookie = config('Cookie'); $cookiePrefix = $cookie->prefix ?? $config->cookiePrefix; diff --git a/system/Session/Session.php b/system/Session/Session.php index 808e5fd65f49..7850fc534266 100644 --- a/system/Session/Session.php +++ b/system/Session/Session.php @@ -182,7 +182,9 @@ public function __construct(SessionHandlerInterface $driver, App $config) $this->cookieSecure = $config->cookieSecure ?? $this->cookieSecure; $this->cookieSameSite = $config->cookieSameSite ?? $this->cookieSameSite; - /** @var CookieConfig */ + /** + * @var CookieConfig $cookie + */ $cookie = config('Cookie'); $this->cookie = new Cookie($this->sessionCookieName, '', [ diff --git a/system/Test/Fabricator.php b/system/Test/Fabricator.php index 65fc10131d04..0fb013cb1820 100644 --- a/system/Test/Fabricator.php +++ b/system/Test/Fabricator.php @@ -233,8 +233,6 @@ public function getOverrides(): array * * @param array $overrides Array of [field => value] * @param bool $persist Whether these overrides should persist through the next operation - * - * @return $this */ public function setOverrides(array $overrides = [], $persist = true): self { @@ -259,8 +257,6 @@ public function getFormatters(): ?array * Set the formatters to use. Will attempt to autodetect if none are available. * * @param array|null $formatters Array of [field => formatter], or null to detect - * - * @return $this */ public function setFormatters(?array $formatters = null): self { @@ -277,8 +273,6 @@ public function setFormatters(?array $formatters = null): self /** * Try to identify the appropriate Faker formatter for each field. - * - * @return $this */ protected function detectFormatters(): self { diff --git a/system/Test/Mock/MockBuilder.php b/system/Test/Mock/MockBuilder.php index a47d76b0f561..63002436b4e4 100644 --- a/system/Test/Mock/MockBuilder.php +++ b/system/Test/Mock/MockBuilder.php @@ -12,12 +12,7 @@ namespace CodeIgniter\Test\Mock; use CodeIgniter\Database\BaseBuilder; -use CodeIgniter\Database\ConnectionInterface; class MockBuilder extends BaseBuilder { - public function __construct($tableName, ConnectionInterface &$db, ?array $options = null) - { - parent::__construct($tableName, $db, $options); - } } diff --git a/system/Throttle/Throttler.php b/system/Throttle/Throttler.php index fe0679a0217b..0bdf8a95522d 100644 --- a/system/Throttle/Throttler.php +++ b/system/Throttle/Throttler.php @@ -139,8 +139,6 @@ public function check(string $key, int $capacity, int $seconds, int $cost = 1): /** * @param string $key The name of the bucket - * - * @return $this */ public function remove(string $key): self { diff --git a/system/Validation/Rules.php b/system/Validation/Rules.php index 1336e9fb87f3..20f558e52be2 100644 --- a/system/Validation/Rules.php +++ b/system/Validation/Rules.php @@ -113,7 +113,7 @@ public function is_not_unique(?string $str, string $field, array $data): bool $row = $row->where($whereField, $whereValue); } - return (bool) ($row->get()->getRow() !== null); + return $row->get()->getRow() !== null; } /** @@ -158,7 +158,7 @@ public function is_unique(?string $str, string $field, array $data): bool $row = $row->where("{$ignoreField} !=", $ignoreValue); } - return (bool) ($row->get()->getRow() === null); + return $row->get()->getRow() === null; } /** diff --git a/tests/system/API/ResponseTraitTest.php b/tests/system/API/ResponseTraitTest.php index fd35469dd5ec..b63b7362a600 100644 --- a/tests/system/API/ResponseTraitTest.php +++ b/tests/system/API/ResponseTraitTest.php @@ -64,8 +64,8 @@ protected function makeController(array $userConfig = [], string $uri = 'http:// } if ($this->request === null) { - $this->request = new MockIncomingRequest((object) $config, new URI($uri), null, new UserAgent()); - $this->response = new MockResponse((object) $config); + $this->request = new MockIncomingRequest($config, new URI($uri), null, new UserAgent()); + $this->response = new MockResponse($config); } // Insert headers into request. diff --git a/tests/system/Cache/Handlers/FileHandlerTest.php b/tests/system/Cache/Handlers/FileHandlerTest.php index de912e4b5e84..ea5a095631e0 100644 --- a/tests/system/Cache/Handlers/FileHandlerTest.php +++ b/tests/system/Cache/Handlers/FileHandlerTest.php @@ -345,7 +345,7 @@ public function __construct() public function getFileInfoTest() { $tmpHandle = tmpfile(); - stream_get_meta_data($tmpHandle)['uri']; + stream_get_meta_data($tmpHandle); return $this->getFileInfo(stream_get_meta_data($tmpHandle)['uri'], [ 'name', diff --git a/tests/system/Cookie/CookieStoreTest.php b/tests/system/Cookie/CookieStoreTest.php index a73403fba6e1..2c588fb3391e 100644 --- a/tests/system/Cookie/CookieStoreTest.php +++ b/tests/system/Cookie/CookieStoreTest.php @@ -110,7 +110,7 @@ public function testCookieDispatching(): void $prod = $cookies['prod']->getOptions(); /** - * @var MockObject&CookieStore + * @var MockObject&CookieStore $store */ $store = $this->getMockBuilder(CookieStore::class) ->setConstructorArgs([$cookies]) diff --git a/tests/system/Database/Live/UpdateTest.php b/tests/system/Database/Live/UpdateTest.php index 665a7f675fe3..f047f16a7bfd 100644 --- a/tests/system/Database/Live/UpdateTest.php +++ b/tests/system/Database/Live/UpdateTest.php @@ -58,8 +58,6 @@ public function testUpdateSetsAllWithoutWhereAndLimit() // This DB doesn't support Where and Limit together // but we don't want it called a "Risky" test. $this->assertTrue(true); - - return; } } @@ -95,8 +93,6 @@ public function testUpdateWithWhereAndLimit() // This DB doesn't support Where and Limit together // but we don't want it called a "Risky" test. $this->assertTrue(true); - - return; } } diff --git a/tests/system/Events/EventsTest.php b/tests/system/Events/EventsTest.php index 65fd7df6365e..222722b1448d 100644 --- a/tests/system/Events/EventsTest.php +++ b/tests/system/Events/EventsTest.php @@ -48,7 +48,7 @@ protected function tearDown(): void public function testInitialize() { /** - * @var Modules + * @var Modules $config */ $config = config('Modules'); $config->aliases = []; diff --git a/tests/system/Pager/PagerTest.php b/tests/system/Pager/PagerTest.php index 99d2bf7102bd..72deb09c2c4c 100644 --- a/tests/system/Pager/PagerTest.php +++ b/tests/system/Pager/PagerTest.php @@ -241,7 +241,7 @@ public function testGetNextURIUsesCurrentURI() $expected = current_url(true); $expected = (string) $expected->setQuery('page_foo=3'); - $this->assertSame((string) $expected, $this->pager->getNextPageURI('foo')); + $this->assertSame($expected, $this->pager->getNextPageURI('foo')); } public function testGetNextURIReturnsNullOnLastPage() @@ -270,7 +270,7 @@ public function testGetPreviousURIUsesCurrentURI() $expected = current_url(true); $expected = (string) $expected->setQuery('page_foo=1'); - $this->assertSame((string) $expected, $this->pager->getPreviousPageURI('foo')); + $this->assertSame($expected, $this->pager->getPreviousPageURI('foo')); } public function testGetNextURIReturnsNullOnFirstPage() @@ -292,7 +292,7 @@ public function testGetNextURIWithQueryStringUsesCurrentURI() $this->pager->store('foo', $_GET['page_foo'] - 1, 12, 70); - $this->assertSame((string) $expected, $this->pager->getNextPageURI('foo')); + $this->assertSame($expected, $this->pager->getNextPageURI('foo')); } public function testGetPreviousURIWithQueryStringUsesCurrentURI() @@ -306,7 +306,7 @@ public function testGetPreviousURIWithQueryStringUsesCurrentURI() $this->pager->store('foo', $_GET['page_foo'] + 1, 12, 70); - $this->assertSame((string) $expected, $this->pager->getPreviousPageURI('foo')); + $this->assertSame($expected, $this->pager->getPreviousPageURI('foo')); } public function testGetOnlyQueries() @@ -453,7 +453,7 @@ public function testBasedURI() $expected = current_url(true); $expected = (string) $expected->setQuery('page_foo=1'); - $this->assertSame((string) $expected, $this->pager->getPreviousPageURI('foo')); + $this->assertSame($expected, $this->pager->getPreviousPageURI('foo')); } public function testAccessPageMoreThanPageCountGetLastPage() diff --git a/tests/system/Session/SessionTest.php b/tests/system/Session/SessionTest.php index b6989b299db0..bb5afaacf515 100644 --- a/tests/system/Session/SessionTest.php +++ b/tests/system/Session/SessionTest.php @@ -180,9 +180,9 @@ public function testGetReturnsItemValueisZero() $session = $this->getInstance(); $session->start(); - $session->set('foo', (int) 0); + $session->set('foo', 0); - $this->assertSame((int) 0, $session->get('foo')); + $this->assertSame(0, $session->get('foo')); } public function testGetReturnsAllWithNoKeys() From 377eddb29b5c4220fee970a0c556ea44274f7460 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 17 Aug 2021 19:08:35 +0700 Subject: [PATCH 2/2] use single line @var --- system/Security/Security.php | 8 ++------ system/Session/Session.php | 4 +--- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/system/Security/Security.php b/system/Security/Security.php index 59a24a0cbd0f..aa6cf6edabad 100644 --- a/system/Security/Security.php +++ b/system/Security/Security.php @@ -125,9 +125,7 @@ class Security implements SecurityInterface */ public function __construct(App $config) { - /** - * @var SecurityConfig $security - */ + /** @var SecurityConfig $security */ $security = config('Security'); // Store CSRF-related configurations @@ -136,9 +134,7 @@ public function __construct(App $config) $this->regenerate = $security->regenerate ?? $config->CSRFRegenerate ?? $this->regenerate; $rawCookieName = $security->cookieName ?? $config->CSRFCookieName ?? $this->cookieName; - /** - * @var CookieConfig $cookie - */ + /** @var CookieConfig $cookie */ $cookie = config('Cookie'); $cookiePrefix = $cookie->prefix ?? $config->cookiePrefix; diff --git a/system/Session/Session.php b/system/Session/Session.php index 7850fc534266..27ba502aea36 100644 --- a/system/Session/Session.php +++ b/system/Session/Session.php @@ -182,9 +182,7 @@ public function __construct(SessionHandlerInterface $driver, App $config) $this->cookieSecure = $config->cookieSecure ?? $this->cookieSecure; $this->cookieSameSite = $config->cookieSameSite ?? $this->cookieSameSite; - /** - * @var CookieConfig $cookie - */ + /** @var CookieConfig $cookie */ $cookie = config('Cookie'); $this->cookie = new Cookie($this->sessionCookieName, '', [