@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare(strict_types=1); |
|
| 1 | +<?php declare(strict_types = 1); |
|
| 2 | 2 | |
| 3 | 3 | namespace Terah\Assert; |
| 4 | 4 | |
@@ -31,22 +31,22 @@ discard block |
||
| 31 | 31 | * @param string $level |
| 32 | 32 | * @return Assert |
| 33 | 33 | */ |
| 34 | -function Assert($value, string $fieldName='', int $code=0, string $error='', string $level=Assert::WARNING) |
|
| 34 | +function Assert($value, string $fieldName = '', int $code = 0, string $error = '', string $level = Assert::WARNING) |
|
| 35 | 35 | { |
| 36 | 36 | $assert = new Assert($value); |
| 37 | - if ( $fieldName ) |
|
| 37 | + if ($fieldName) |
|
| 38 | 38 | { |
| 39 | 39 | $assert->fieldName($fieldName); |
| 40 | 40 | } |
| 41 | - if ( $code ) |
|
| 41 | + if ($code) |
|
| 42 | 42 | { |
| 43 | 43 | $assert->code($code); |
| 44 | 44 | } |
| 45 | - if ( $error ) |
|
| 45 | + if ($error) |
|
| 46 | 46 | { |
| 47 | 47 | $assert->error($error); |
| 48 | 48 | } |
| 49 | - if ( $level ) |
|
| 49 | + if ($level) |
|
| 50 | 50 | { |
| 51 | 51 | $assert->level($level); |
| 52 | 52 | } |
@@ -64,22 +64,22 @@ discard block |
||
| 64 | 64 | * @param string $level |
| 65 | 65 | * @return Assert |
| 66 | 66 | */ |
| 67 | -function Validate($value, string $fieldName='', int $code=0, string $error='', string $level=Assert::WARNING) |
|
| 67 | +function Validate($value, string $fieldName = '', int $code = 0, string $error = '', string $level = Assert::WARNING) |
|
| 68 | 68 | { |
| 69 | 69 | $assert = new Assert($value); |
| 70 | - if ( $fieldName ) |
|
| 70 | + if ($fieldName) |
|
| 71 | 71 | { |
| 72 | 72 | $assert->fieldName($fieldName); |
| 73 | 73 | } |
| 74 | - if ( $code ) |
|
| 74 | + if ($code) |
|
| 75 | 75 | { |
| 76 | 76 | $assert->code($code); |
| 77 | 77 | } |
| 78 | - if ( $error ) |
|
| 78 | + if ($error) |
|
| 79 | 79 | { |
| 80 | 80 | $assert->error($error); |
| 81 | 81 | } |
| 82 | - if ( $level ) |
|
| 82 | + if ($level) |
|
| 83 | 83 | { |
| 84 | 84 | $assert->level($level); |
| 85 | 85 | } |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php declare(strict_types=1); |
|
| 1 | +<?php declare(strict_types = 1); |
|
| 2 | 2 | |
| 3 | 3 | namespace Terah\Assert; |
| 4 | 4 | |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | * @param string $level |
| 42 | 42 | * @param string $propertyPath |
| 43 | 43 | */ |
| 44 | - public function __construct(string $message, int $code, string $fieldName='', $value='', array $constraints=[], string $level='critical', string $propertyPath='') |
|
| 44 | + public function __construct(string $message, int $code, string $fieldName = '', $value = '', array $constraints = [ ], string $level = 'critical', string $propertyPath = '') |
|
| 45 | 45 | { |
| 46 | 46 | parent::__construct($message, $code); |
| 47 | 47 | $this->fieldName = $fieldName; |
@@ -49,14 +49,14 @@ discard block |
||
| 49 | 49 | $this->constraints = $constraints; |
| 50 | 50 | $this->level = $level; |
| 51 | 51 | $this->propertyPath = $propertyPath; |
| 52 | - foreach ( $this->getTrace() as $point ) |
|
| 52 | + foreach ($this->getTrace() as $point) |
|
| 53 | 53 | { |
| 54 | - if ( $this->location ) |
|
| 54 | + if ($this->location) |
|
| 55 | 55 | { |
| 56 | 56 | continue; |
| 57 | 57 | } |
| 58 | - $class = $point['class'] ??0?: ''; |
|
| 59 | - if ( $class !== Assert::class ) |
|
| 58 | + $class = $point[ 'class' ] ??0 ?: ''; |
|
| 59 | + if ($class !== Assert::class) |
|
| 60 | 60 | { |
| 61 | 61 | $this->location = (object)$point; |
| 62 | 62 | } |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | */ |
| 125 | 125 | public function getPropertyPathAndCallingLocation() : string |
| 126 | 126 | { |
| 127 | - return $this->getPropertyPath() . ' in ' . $this->getCallingFileAndLine(); |
|
| 127 | + return $this->getPropertyPath().' in '.$this->getCallingFileAndLine(); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | /** |
@@ -135,15 +135,15 @@ discard block |
||
| 135 | 135 | */ |
| 136 | 136 | protected function getCallingFileAndLine() : string |
| 137 | 137 | { |
| 138 | - foreach ( $this->getTrace() as $trace ) |
|
| 138 | + foreach ($this->getTrace() as $trace) |
|
| 139 | 139 | { |
| 140 | 140 | $trace = (object)$trace; |
| 141 | - if ( empty($trace->file) ) |
|
| 141 | + if (empty($trace->file)) |
|
| 142 | 142 | { |
| 143 | 143 | continue; |
| 144 | 144 | } |
| 145 | 145 | $file = static::beforeLast('.php', static::afterLast('/', $trace->file)); |
| 146 | - if ( in_array($file, ['AssertionChain', 'Assertion']) ) |
|
| 146 | + if (in_array($file, [ 'AssertionChain', 'Assertion' ])) |
|
| 147 | 147 | { |
| 148 | 148 | continue; |
| 149 | 149 | } |
@@ -170,9 +170,9 @@ discard block |
||
| 170 | 170 | * @param bool $returnOriginal |
| 171 | 171 | * @return string |
| 172 | 172 | */ |
| 173 | - public static function afterLast(string $needle, string $haystack, bool $returnOriginal=false) : string |
|
| 173 | + public static function afterLast(string $needle, string $haystack, bool $returnOriginal = false) : string |
|
| 174 | 174 | { |
| 175 | - if ( static::strrevpos($haystack, $needle) !== -1 ) |
|
| 175 | + if (static::strrevpos($haystack, $needle) !== -1) |
|
| 176 | 176 | { |
| 177 | 177 | return mb_substr($haystack, static::strrevpos($haystack, $needle) + mb_strlen($needle)); |
| 178 | 178 | } |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | */ |
| 200 | 200 | public static function beforeLast(string $needle, string $haystack) : string |
| 201 | 201 | { |
| 202 | - $position = static::strrevpos($haystack, $needle); |
|
| 202 | + $position = static::strrevpos($haystack, $needle); |
|
| 203 | 203 | |
| 204 | 204 | return $position === -1 ? '' : mb_substr($haystack, 0, static::strrevpos($haystack, $needle)); |
| 205 | 205 | } |