From ae1bb3771b012b52d603eccaa23c5d8379ea3043 Mon Sep 17 00:00:00 2001 From: Norbert Orzechowicz Date: Sun, 4 Feb 2018 22:16:17 +0100 Subject: [PATCH] Code cleanup --- src/Matcher/Pattern/Expander/Contains.php | 14 +--------- src/Matcher/Pattern/Expander/EndsWith.php | 2 +- src/Matcher/Pattern/Expander/IsDateTime.php | 2 +- src/Matcher/Pattern/Expander/IsEmail.php | 2 +- src/Matcher/Pattern/Expander/IsUrl.php | 2 +- src/Matcher/Pattern/Expander/OneOf.php | 4 +-- src/Matcher/Pattern/Expander/Repeat.php | 30 --------------------- src/Matcher/Pattern/Expander/StartsWith.php | 4 +-- 8 files changed, 9 insertions(+), 51 deletions(-) diff --git a/src/Matcher/Pattern/Expander/Contains.php b/src/Matcher/Pattern/Expander/Contains.php index 8fe63442..e718262d 100644 --- a/src/Matcher/Pattern/Expander/Contains.php +++ b/src/Matcher/Pattern/Expander/Contains.php @@ -11,24 +11,12 @@ final class Contains implements PatternExpander { const NAME = 'contains'; - /** - * @var null|string - */ private $error; - /** - * @var - */ private $string; - /** - * @var bool - */ private $ignoreCase; - /** - * {@inheritdoc} - */ public static function is(string $name) : bool { return self::NAME === $name; @@ -48,7 +36,7 @@ public function match($value) : bool } $contains = $this->ignoreCase - ? \mb_strpos(\mb_strtolower($value), \mb_strtolower($this->string)) + ? \mb_stripos($value, $this->string) : \mb_strpos($value, $this->string); if ($contains === false) { diff --git a/src/Matcher/Pattern/Expander/EndsWith.php b/src/Matcher/Pattern/Expander/EndsWith.php index 221dcbe5..74d85db4 100644 --- a/src/Matcher/Pattern/Expander/EndsWith.php +++ b/src/Matcher/Pattern/Expander/EndsWith.php @@ -56,7 +56,7 @@ public function getError() return $this->error; } - protected function matchValue(string $value) : bool + private function matchValue(string $value) : bool { return $this->ignoreCase ? \mb_substr(\mb_strtolower($value), -\mb_strlen(\mb_strtolower($this->stringEnding))) === \mb_strtolower($this->stringEnding) diff --git a/src/Matcher/Pattern/Expander/IsDateTime.php b/src/Matcher/Pattern/Expander/IsDateTime.php index d6d0ec62..a3418cb1 100644 --- a/src/Matcher/Pattern/Expander/IsDateTime.php +++ b/src/Matcher/Pattern/Expander/IsDateTime.php @@ -38,7 +38,7 @@ public function getError() return $this->error; } - protected function matchValue(string $value) : bool + private function matchValue(string $value) : bool { try { new \DateTime($value); diff --git a/src/Matcher/Pattern/Expander/IsEmail.php b/src/Matcher/Pattern/Expander/IsEmail.php index b5cf7733..d5ad8dc2 100644 --- a/src/Matcher/Pattern/Expander/IsEmail.php +++ b/src/Matcher/Pattern/Expander/IsEmail.php @@ -38,7 +38,7 @@ public function getError() return $this->error; } - protected function matchValue(string $value) : bool + private function matchValue(string $value) : bool { try { return false !== \filter_var($value, FILTER_VALIDATE_EMAIL); diff --git a/src/Matcher/Pattern/Expander/IsUrl.php b/src/Matcher/Pattern/Expander/IsUrl.php index 8f3497cb..05429657 100644 --- a/src/Matcher/Pattern/Expander/IsUrl.php +++ b/src/Matcher/Pattern/Expander/IsUrl.php @@ -38,7 +38,7 @@ public function getError() return $this->error; } - protected function matchValue(string $value) : bool + private function matchValue(string $value) : bool { try { return false !== \filter_var($value, FILTER_VALIDATE_URL); diff --git a/src/Matcher/Pattern/Expander/OneOf.php b/src/Matcher/Pattern/Expander/OneOf.php index 2174706e..f6bd0f1b 100644 --- a/src/Matcher/Pattern/Expander/OneOf.php +++ b/src/Matcher/Pattern/Expander/OneOf.php @@ -14,9 +14,9 @@ final class OneOf implements PatternExpander /** * @var PatternExpander[] */ - protected $expanders; + private $expanders; - protected $error; + private $error; public function __construct() { diff --git a/src/Matcher/Pattern/Expander/Repeat.php b/src/Matcher/Pattern/Expander/Repeat.php index 27d8cb07..cb7b24ff 100644 --- a/src/Matcher/Pattern/Expander/Repeat.php +++ b/src/Matcher/Pattern/Expander/Repeat.php @@ -13,37 +13,19 @@ final class Repeat implements PatternExpander { const NAME = 'repeat'; - /** - * @var null|string - */ private $error; - /** - * @var string - */ private $pattern; - /** - * @var bool - */ private $isStrict; - /** - * @var bool - */ private $isScalar; - /** - * {@inheritdoc} - */ public static function is(string $name) : bool { return self::NAME === $name; } - /** - * @param $value - */ public function __construct(string $pattern, bool $isStrict = true) { if (!\is_string($pattern)) { @@ -62,10 +44,6 @@ public function __construct(string $pattern, bool $isStrict = true) } } - /** - * @param $values - * @return bool - */ public function match($values) : bool { if (!\is_array($values)) { @@ -83,19 +61,11 @@ public function match($values) : bool return $this->matchJson($values, $matcher); } - /** - * @return string|null - */ public function getError() { return $this->error; } - /** - * @param array $values - * @param Matcher $matcher - * @return bool - */ private function matchScalar(array $values, Matcher $matcher) : bool { foreach ($values as $index => $value) { diff --git a/src/Matcher/Pattern/Expander/StartsWith.php b/src/Matcher/Pattern/Expander/StartsWith.php index 01e01719..14d12c0a 100644 --- a/src/Matcher/Pattern/Expander/StartsWith.php +++ b/src/Matcher/Pattern/Expander/StartsWith.php @@ -57,10 +57,10 @@ public function getError() return $this->error; } - protected function matchValue(string $value) : bool + private function matchValue(string $value) : bool { return $this->ignoreCase - ? \mb_strpos(\mb_strtolower($value), \mb_strtolower($this->stringBeginning)) !== 0 + ? \mb_stripos($value, $this->stringBeginning) !== 0 : \mb_strpos($value, $this->stringBeginning) !== 0; } }