From 19962e9aa6789699ea7bdf94b468c2490db94ac0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Machulda?= Date: Mon, 13 May 2024 15:49:23 +0200 Subject: [PATCH] Refactor: Remove nette/utils dependency --- composer.json | 1 - src/Sniffs/Naming/AbstractClassNameSniff.php | 3 +-- src/Sniffs/Naming/ClassNameSuffixByParentSniff.php | 11 +++++------ src/Sniffs/Naming/InterfaceNameSniff.php | 3 +-- src/Sniffs/Naming/TraitNameSniff.php | 3 +-- 5 files changed, 8 insertions(+), 13 deletions(-) diff --git a/composer.json b/composer.json index 38354b5..400f9a2 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,6 @@ "require": { "php": "^8.0", "friendsofphp/php-cs-fixer": "^3.0", - "nette/utils": "^3.2", "slevomat/coding-standard": "^8.0", "squizlabs/php_codesniffer": "^3.9", "symplify/easy-coding-standard": "^12.1.5" diff --git a/src/Sniffs/Naming/AbstractClassNameSniff.php b/src/Sniffs/Naming/AbstractClassNameSniff.php index 41c10d9..54a1503 100644 --- a/src/Sniffs/Naming/AbstractClassNameSniff.php +++ b/src/Sniffs/Naming/AbstractClassNameSniff.php @@ -28,7 +28,6 @@ namespace Lmc\CodingStandard\Sniffs\Naming; -use Nette\Utils\Strings; use PHP_CodeSniffer\Files\File; use PHP_CodeSniffer\Sniffs\Sniff; @@ -70,7 +69,7 @@ private function shouldBeSkipped(): bool return true; } - return Strings::startsWith($className, 'Abstract'); + return str_starts_with($className, 'Abstract'); } private function isClassAbstract(): bool diff --git a/src/Sniffs/Naming/ClassNameSuffixByParentSniff.php b/src/Sniffs/Naming/ClassNameSuffixByParentSniff.php index ee66c17..268f5e5 100644 --- a/src/Sniffs/Naming/ClassNameSuffixByParentSniff.php +++ b/src/Sniffs/Naming/ClassNameSuffixByParentSniff.php @@ -30,7 +30,6 @@ use Lmc\CodingStandard\Helper\Naming; use Lmc\CodingStandard\Helper\SniffClassWrapper; -use Nette\Utils\Strings; use PHP_CodeSniffer\Files\File; use PHP_CodeSniffer\Sniffs\Sniff; @@ -101,7 +100,7 @@ private function processType(File $file, string $currentParentType, string $clas // the class that implements $currentParentType, should end with $suffix $suffix = $this->resolveExpectedSuffix($parentType); - if (Strings::endsWith($className, $suffix)) { + if (str_ends_with($className, $suffix)) { continue; } @@ -123,12 +122,12 @@ private function getClassToSuffixMap(): array */ private function resolveExpectedSuffix(string $parentType): string { - if (Strings::endsWith($parentType, 'Interface')) { - $parentType = Strings::substring($parentType, 0, -mb_strlen('Interface')); + if (str_ends_with($parentType, 'Interface')) { + $parentType = mb_substr($parentType, 0, -mb_strlen('Interface'), 'UTF-8'); } - if (Strings::startsWith($parentType, 'Abstract')) { - $parentType = Strings::substring($parentType, mb_strlen('Abstract')); + if (str_starts_with($parentType, 'Abstract')) { + $parentType = mb_substr($parentType, mb_strlen('Abstract'), null, 'UTF-8'); } return $parentType; diff --git a/src/Sniffs/Naming/InterfaceNameSniff.php b/src/Sniffs/Naming/InterfaceNameSniff.php index 497db63..b7f3b20 100644 --- a/src/Sniffs/Naming/InterfaceNameSniff.php +++ b/src/Sniffs/Naming/InterfaceNameSniff.php @@ -28,7 +28,6 @@ namespace Lmc\CodingStandard\Sniffs\Naming; -use Nette\Utils\Strings; use PHP_CodeSniffer\Files\File; use PHP_CodeSniffer\Sniffs\Sniff; @@ -56,7 +55,7 @@ public function process(File $phpcsFile, $stackPtr): void $this->file = $phpcsFile; $this->position = $stackPtr; - if (Strings::endsWith($this->getInterfaceName(), 'Interface')) { + if (str_ends_with($this->getInterfaceName(), 'Interface')) { return; } diff --git a/src/Sniffs/Naming/TraitNameSniff.php b/src/Sniffs/Naming/TraitNameSniff.php index d977e3a..357c80e 100644 --- a/src/Sniffs/Naming/TraitNameSniff.php +++ b/src/Sniffs/Naming/TraitNameSniff.php @@ -28,7 +28,6 @@ namespace Lmc\CodingStandard\Sniffs\Naming; -use Nette\Utils\Strings; use PHP_CodeSniffer\Files\File; use PHP_CodeSniffer\Sniffs\Sniff; @@ -56,7 +55,7 @@ public function process(File $phpcsFile, $stackPtr): void $this->file = $phpcsFile; $this->position = $stackPtr; - if (Strings::endsWith($this->getTraitName(), 'Trait')) { + if (str_ends_with($this->getTraitName(), 'Trait')) { return; }