@@ -16,74 +16,74 @@ |
||
| 16 | 16 | trait Contains |
| 17 | 17 | { |
| 18 | 18 | /** |
| 19 | - * Returns true if the string contains $needle, false otherwise. |
|
| 20 | - * |
|
| 21 | - * By default the comparison is case-sensitive, but can be made |
|
| 22 | - * insensitive by setting $caseSensitive to false. |
|
| 23 | - * |
|
| 24 | - * @param string $needle Substring to look for. |
|
| 25 | - * |
|
| 26 | - * @param bool $caseSensitive Whether or not to enforce case-sensitivity. |
|
| 27 | - * |
|
| 28 | - * @return bool Whether or not $str contains $needle. |
|
| 29 | - */ |
|
| 30 | - public function contains($needle, $caseSensitive = true) |
|
| 31 | - { |
|
| 32 | - if ($caseSensitive) |
|
| 33 | - { |
|
| 34 | - return (UTF8::strpos($this->scalarString, $needle, 0, $this->encoding) !== false); |
|
| 35 | - } |
|
| 36 | - else |
|
| 37 | - { |
|
| 38 | - return (UTF8::stripos($this->scalarString, $needle, 0, $this->encoding) !== false); |
|
| 39 | - } |
|
| 40 | - } |
|
| 19 | + * Returns true if the string contains $needle, false otherwise. |
|
| 20 | + * |
|
| 21 | + * By default the comparison is case-sensitive, but can be made |
|
| 22 | + * insensitive by setting $caseSensitive to false. |
|
| 23 | + * |
|
| 24 | + * @param string $needle Substring to look for. |
|
| 25 | + * |
|
| 26 | + * @param bool $caseSensitive Whether or not to enforce case-sensitivity. |
|
| 27 | + * |
|
| 28 | + * @return bool Whether or not $str contains $needle. |
|
| 29 | + */ |
|
| 30 | + public function contains($needle, $caseSensitive = true) |
|
| 31 | + { |
|
| 32 | + if ($caseSensitive) |
|
| 33 | + { |
|
| 34 | + return (UTF8::strpos($this->scalarString, $needle, 0, $this->encoding) !== false); |
|
| 35 | + } |
|
| 36 | + else |
|
| 37 | + { |
|
| 38 | + return (UTF8::stripos($this->scalarString, $needle, 0, $this->encoding) !== false); |
|
| 39 | + } |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Returns true if the string contains all $needles, false otherwise. |
|
| 44 | - * |
|
| 45 | - * By default the comparison is case-sensitive, but can be made |
|
| 46 | - * insensitive by setting $caseSensitive to false. |
|
| 47 | - * |
|
| 48 | - * @param array $needles SubStrings to look for. |
|
| 49 | - * |
|
| 50 | - * @param bool $caseSensitive Whether or not to enforce case-sensitivity. |
|
| 51 | - * |
|
| 52 | - * @return bool Whether or not $str contains $needle. |
|
| 53 | - */ |
|
| 54 | - public function containsAll($needles, $caseSensitive = true) |
|
| 55 | - { |
|
| 56 | - if (empty($needles)) return false; |
|
| 42 | + /** |
|
| 43 | + * Returns true if the string contains all $needles, false otherwise. |
|
| 44 | + * |
|
| 45 | + * By default the comparison is case-sensitive, but can be made |
|
| 46 | + * insensitive by setting $caseSensitive to false. |
|
| 47 | + * |
|
| 48 | + * @param array $needles SubStrings to look for. |
|
| 49 | + * |
|
| 50 | + * @param bool $caseSensitive Whether or not to enforce case-sensitivity. |
|
| 51 | + * |
|
| 52 | + * @return bool Whether or not $str contains $needle. |
|
| 53 | + */ |
|
| 54 | + public function containsAll($needles, $caseSensitive = true) |
|
| 55 | + { |
|
| 56 | + if (empty($needles)) return false; |
|
| 57 | 57 | |
| 58 | - foreach ($needles as $needle) |
|
| 59 | - { |
|
| 60 | - if (!$this->contains($needle, $caseSensitive)) return false; |
|
| 61 | - } |
|
| 58 | + foreach ($needles as $needle) |
|
| 59 | + { |
|
| 60 | + if (!$this->contains($needle, $caseSensitive)) return false; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - return true; |
|
| 64 | - } |
|
| 63 | + return true; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * Returns true if the string contains any $needles, false otherwise. |
|
| 68 | - * |
|
| 69 | - * By default the comparison is case-sensitive, but can be made |
|
| 70 | - * insensitive by setting $caseSensitive to false. |
|
| 71 | - * |
|
| 72 | - * @param array $needles SubStrings to look for. |
|
| 73 | - * |
|
| 74 | - * @param bool $caseSensitive Whether or not to enforce case-sensitivity. |
|
| 75 | - * |
|
| 76 | - * @return bool Whether or not $str contains $needle. |
|
| 77 | - */ |
|
| 78 | - public function containsAny($needles, $caseSensitive = true) |
|
| 79 | - { |
|
| 80 | - if (empty($needles)) return false; |
|
| 66 | + /** |
|
| 67 | + * Returns true if the string contains any $needles, false otherwise. |
|
| 68 | + * |
|
| 69 | + * By default the comparison is case-sensitive, but can be made |
|
| 70 | + * insensitive by setting $caseSensitive to false. |
|
| 71 | + * |
|
| 72 | + * @param array $needles SubStrings to look for. |
|
| 73 | + * |
|
| 74 | + * @param bool $caseSensitive Whether or not to enforce case-sensitivity. |
|
| 75 | + * |
|
| 76 | + * @return bool Whether or not $str contains $needle. |
|
| 77 | + */ |
|
| 78 | + public function containsAny($needles, $caseSensitive = true) |
|
| 79 | + { |
|
| 80 | + if (empty($needles)) return false; |
|
| 81 | 81 | |
| 82 | - foreach ($needles as $needle) |
|
| 83 | - { |
|
| 84 | - if ($this->contains($needle, $caseSensitive)) return true; |
|
| 85 | - } |
|
| 82 | + foreach ($needles as $needle) |
|
| 83 | + { |
|
| 84 | + if ($this->contains($needle, $caseSensitive)) return true; |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - return false; |
|
| 88 | - } |
|
| 87 | + return false; |
|
| 88 | + } |
|
| 89 | 89 | } |
@@ -32,8 +32,7 @@ discard block |
||
| 32 | 32 | if ($caseSensitive) |
| 33 | 33 | { |
| 34 | 34 | return (UTF8::strpos($this->scalarString, $needle, 0, $this->encoding) !== false); |
| 35 | - } |
|
| 36 | - else |
|
| 35 | + } else |
|
| 37 | 36 | { |
| 38 | 37 | return (UTF8::stripos($this->scalarString, $needle, 0, $this->encoding) !== false); |
| 39 | 38 | } |
@@ -53,11 +52,15 @@ discard block |
||
| 53 | 52 | */ |
| 54 | 53 | public function containsAll($needles, $caseSensitive = true) |
| 55 | 54 | { |
| 56 | - if (empty($needles)) return false; |
|
| 55 | + if (empty($needles)) { |
|
| 56 | + return false; |
|
| 57 | + } |
|
| 57 | 58 | |
| 58 | 59 | foreach ($needles as $needle) |
| 59 | 60 | { |
| 60 | - if (!$this->contains($needle, $caseSensitive)) return false; |
|
| 61 | + if (!$this->contains($needle, $caseSensitive)) { |
|
| 62 | + return false; |
|
| 63 | + } |
|
| 61 | 64 | } |
| 62 | 65 | |
| 63 | 66 | return true; |
@@ -77,11 +80,15 @@ discard block |
||
| 77 | 80 | */ |
| 78 | 81 | public function containsAny($needles, $caseSensitive = true) |
| 79 | 82 | { |
| 80 | - if (empty($needles)) return false; |
|
| 83 | + if (empty($needles)) { |
|
| 84 | + return false; |
|
| 85 | + } |
|
| 81 | 86 | |
| 82 | 87 | foreach ($needles as $needle) |
| 83 | 88 | { |
| 84 | - if ($this->contains($needle, $caseSensitive)) return true; |
|
| 89 | + if ($this->contains($needle, $caseSensitive)) { |
|
| 90 | + return true; |
|
| 91 | + } |
|
| 85 | 92 | } |
| 86 | 93 | |
| 87 | 94 | return false; |
@@ -16,145 +16,145 @@ discard block |
||
| 16 | 16 | |
| 17 | 17 | trait Regx |
| 18 | 18 | { |
| 19 | - /** |
|
| 20 | - * The delimiter we will use for all regular expressions. |
|
| 21 | - * |
|
| 22 | - * @see http://php.net/manual/en/regexp.reference.delimiters.php |
|
| 23 | - * |
|
| 24 | - * @var string |
|
| 25 | - */ |
|
| 26 | - protected $regexDelimiter = '/'; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * Allows you to change the the default regular expression delimiter. |
|
| 30 | - * |
|
| 31 | - * @param string $value The delimiter to use for all future expressions. |
|
| 32 | - * |
|
| 33 | - * @return static |
|
| 34 | - */ |
|
| 35 | - public function setRegexDelimiter($value) |
|
| 36 | - { |
|
| 37 | - $this->regexDelimiter = $value; |
|
| 38 | - |
|
| 39 | - return $this; |
|
| 40 | - } |
|
| 19 | + /** |
|
| 20 | + * The delimiter we will use for all regular expressions. |
|
| 21 | + * |
|
| 22 | + * @see http://php.net/manual/en/regexp.reference.delimiters.php |
|
| 23 | + * |
|
| 24 | + * @var string |
|
| 25 | + */ |
|
| 26 | + protected $regexDelimiter = '/'; |
|
| 41 | 27 | |
| 42 | 28 | /** |
| 43 | - * Returns true if the string matches the supplied pattern, false otherwise. |
|
| 44 | - * |
|
| 45 | - * @param string $pattern Regex pattern to match against. |
|
| 46 | - * |
|
| 47 | - * @param string $options Matching conditions to be used. |
|
| 48 | - * |
|
| 49 | - * @return bool |
|
| 50 | - * |
|
| 51 | - * @throws PcreException When PCRE Error occurs. |
|
| 52 | - */ |
|
| 53 | - public function regexMatch($pattern, $options = '') |
|
| 54 | - { |
|
| 55 | - // Ensure the options contain the "u" modifier. |
|
| 56 | - if (!$this->newSelf($options)->contains('u')) $options .= 'u'; |
|
| 57 | - |
|
| 58 | - // Build the expression |
|
| 59 | - $expression = |
|
| 60 | - $this->regexDelimiter. |
|
| 61 | - $pattern. |
|
| 62 | - $this->regexDelimiter. |
|
| 63 | - $options |
|
| 64 | - ; |
|
| 65 | - |
|
| 66 | - // Run the expression |
|
| 67 | - $result = preg_match($expression, $this->scalarString); |
|
| 68 | - |
|
| 69 | - // If no errors return true or false based on number of matches found. |
|
| 70 | - if ($result !== false) return $result === 1; |
|
| 71 | - |
|
| 72 | - // Otherwise throw with last known PCRE Error. |
|
| 29 | + * Allows you to change the the default regular expression delimiter. |
|
| 30 | + * |
|
| 31 | + * @param string $value The delimiter to use for all future expressions. |
|
| 32 | + * |
|
| 33 | + * @return static |
|
| 34 | + */ |
|
| 35 | + public function setRegexDelimiter($value) |
|
| 36 | + { |
|
| 37 | + $this->regexDelimiter = $value; |
|
| 38 | + |
|
| 39 | + return $this; |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * Returns true if the string matches the supplied pattern, false otherwise. |
|
| 44 | + * |
|
| 45 | + * @param string $pattern Regex pattern to match against. |
|
| 46 | + * |
|
| 47 | + * @param string $options Matching conditions to be used. |
|
| 48 | + * |
|
| 49 | + * @return bool |
|
| 50 | + * |
|
| 51 | + * @throws PcreException When PCRE Error occurs. |
|
| 52 | + */ |
|
| 53 | + public function regexMatch($pattern, $options = '') |
|
| 54 | + { |
|
| 55 | + // Ensure the options contain the "u" modifier. |
|
| 56 | + if (!$this->newSelf($options)->contains('u')) $options .= 'u'; |
|
| 57 | + |
|
| 58 | + // Build the expression |
|
| 59 | + $expression = |
|
| 60 | + $this->regexDelimiter. |
|
| 61 | + $pattern. |
|
| 62 | + $this->regexDelimiter. |
|
| 63 | + $options |
|
| 64 | + ; |
|
| 65 | + |
|
| 66 | + // Run the expression |
|
| 67 | + $result = preg_match($expression, $this->scalarString); |
|
| 68 | + |
|
| 69 | + // If no errors return true or false based on number of matches found. |
|
| 70 | + if ($result !== false) return $result === 1; |
|
| 71 | + |
|
| 72 | + // Otherwise throw with last known PCRE Error. |
|
| 73 | 73 | throw new PcreException(); |
| 74 | - } |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * Given an expression with capture groups, this will return those captures. |
|
| 78 | - * |
|
| 79 | - * Basically this is the same as `regexMatch()` but returns the array |
|
| 80 | - * of matches from `preg_match()` where as `regexMatch()` just returns |
|
| 81 | - * a boolean result. |
|
| 82 | - * |
|
| 83 | - * @param string $pattern Regex pattern to match against. |
|
| 84 | - * |
|
| 85 | - * @param string $options Matching conditions to be used. |
|
| 86 | - * |
|
| 87 | - * @return array The matches discovered by `preg_match()`. |
|
| 88 | - * |
|
| 89 | - * @throws PcreException When PCRE Error occurs. |
|
| 90 | - */ |
|
| 91 | - public function regexExtract($pattern, $options = '') |
|
| 92 | - { |
|
| 93 | - // Define the array that will be filled by preg_match(). |
|
| 94 | - $matches = []; |
|
| 95 | - |
|
| 96 | - // Ensure the options contain the "u" modifier. |
|
| 97 | - if (!$this->newSelf($options)->contains('u')) $options .= 'u'; |
|
| 98 | - |
|
| 99 | - // Build the expression |
|
| 100 | - $expression = |
|
| 101 | - $this->regexDelimiter. |
|
| 102 | - $pattern. |
|
| 103 | - $this->regexDelimiter. |
|
| 104 | - $options |
|
| 105 | - ; |
|
| 106 | - |
|
| 107 | - // Run the expression |
|
| 108 | - $result = preg_match($expression, $this->scalarString, $matches); |
|
| 109 | - |
|
| 110 | - // If no errors return the $matches array |
|
| 111 | - if ($result !== false) return $this->newSelfs($matches); |
|
| 112 | - |
|
| 113 | - // Otherwise throw with last known PCRE Error. |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * Given an expression with capture groups, this will return those captures. |
|
| 78 | + * |
|
| 79 | + * Basically this is the same as `regexMatch()` but returns the array |
|
| 80 | + * of matches from `preg_match()` where as `regexMatch()` just returns |
|
| 81 | + * a boolean result. |
|
| 82 | + * |
|
| 83 | + * @param string $pattern Regex pattern to match against. |
|
| 84 | + * |
|
| 85 | + * @param string $options Matching conditions to be used. |
|
| 86 | + * |
|
| 87 | + * @return array The matches discovered by `preg_match()`. |
|
| 88 | + * |
|
| 89 | + * @throws PcreException When PCRE Error occurs. |
|
| 90 | + */ |
|
| 91 | + public function regexExtract($pattern, $options = '') |
|
| 92 | + { |
|
| 93 | + // Define the array that will be filled by preg_match(). |
|
| 94 | + $matches = []; |
|
| 95 | + |
|
| 96 | + // Ensure the options contain the "u" modifier. |
|
| 97 | + if (!$this->newSelf($options)->contains('u')) $options .= 'u'; |
|
| 98 | + |
|
| 99 | + // Build the expression |
|
| 100 | + $expression = |
|
| 101 | + $this->regexDelimiter. |
|
| 102 | + $pattern. |
|
| 103 | + $this->regexDelimiter. |
|
| 104 | + $options |
|
| 105 | + ; |
|
| 106 | + |
|
| 107 | + // Run the expression |
|
| 108 | + $result = preg_match($expression, $this->scalarString, $matches); |
|
| 109 | + |
|
| 110 | + // If no errors return the $matches array |
|
| 111 | + if ($result !== false) return $this->newSelfs($matches); |
|
| 112 | + |
|
| 113 | + // Otherwise throw with last known PCRE Error. |
|
| 114 | 114 | throw new PcreException(); |
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * Replaces all occurrences of $pattern in $str by $replacement. |
|
| 119 | - * |
|
| 120 | - * @param string $pattern The regular expression pattern. |
|
| 121 | - * |
|
| 122 | - * @param string $replacement The string to replace with. |
|
| 123 | - * |
|
| 124 | - * @param string $options Matching conditions to be used. |
|
| 125 | - * |
|
| 126 | - * @return static Resulting string after the replacements |
|
| 127 | - * |
|
| 128 | - * @throws PcreException When PCRE Error occurs. |
|
| 129 | - */ |
|
| 130 | - public function regexReplace($pattern, $replacement, $options = '') |
|
| 131 | - { |
|
| 132 | - // The original regexReplace method in danielstjules/Stringy used |
|
| 133 | - // mb_ereg_replace() which supports an "r" flag, PCRE does not. |
|
| 134 | - if ($options === 'msr') $options = 'ms'; |
|
| 135 | - |
|
| 136 | - // Ensure the options contain the "u" modifier. |
|
| 137 | - if (!$this->newSelf($options)->contains('u')) $options .= 'u'; |
|
| 138 | - |
|
| 139 | - // Build the expression |
|
| 140 | - $expression = |
|
| 141 | - $this->regexDelimiter. |
|
| 142 | - $pattern. |
|
| 143 | - $this->regexDelimiter. |
|
| 144 | - $options |
|
| 145 | - ; |
|
| 146 | - |
|
| 147 | - // Run the regular expression replacement |
|
| 148 | - $replaced = preg_replace($expression, $replacement, $this->scalarString); |
|
| 149 | - |
|
| 150 | - // If no errors return the replacement |
|
| 151 | - if ($replaced !== null) return $this->newSelf($replaced); |
|
| 152 | - |
|
| 153 | - // Otherwise throw with last known PCRE Error. |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * Replaces all occurrences of $pattern in $str by $replacement. |
|
| 119 | + * |
|
| 120 | + * @param string $pattern The regular expression pattern. |
|
| 121 | + * |
|
| 122 | + * @param string $replacement The string to replace with. |
|
| 123 | + * |
|
| 124 | + * @param string $options Matching conditions to be used. |
|
| 125 | + * |
|
| 126 | + * @return static Resulting string after the replacements |
|
| 127 | + * |
|
| 128 | + * @throws PcreException When PCRE Error occurs. |
|
| 129 | + */ |
|
| 130 | + public function regexReplace($pattern, $replacement, $options = '') |
|
| 131 | + { |
|
| 132 | + // The original regexReplace method in danielstjules/Stringy used |
|
| 133 | + // mb_ereg_replace() which supports an "r" flag, PCRE does not. |
|
| 134 | + if ($options === 'msr') $options = 'ms'; |
|
| 135 | + |
|
| 136 | + // Ensure the options contain the "u" modifier. |
|
| 137 | + if (!$this->newSelf($options)->contains('u')) $options .= 'u'; |
|
| 138 | + |
|
| 139 | + // Build the expression |
|
| 140 | + $expression = |
|
| 141 | + $this->regexDelimiter. |
|
| 142 | + $pattern. |
|
| 143 | + $this->regexDelimiter. |
|
| 144 | + $options |
|
| 145 | + ; |
|
| 146 | + |
|
| 147 | + // Run the regular expression replacement |
|
| 148 | + $replaced = preg_replace($expression, $replacement, $this->scalarString); |
|
| 149 | + |
|
| 150 | + // If no errors return the replacement |
|
| 151 | + if ($replaced !== null) return $this->newSelf($replaced); |
|
| 152 | + |
|
| 153 | + // Otherwise throw with last known PCRE Error. |
|
| 154 | 154 | throw new PcreException(); |
| 155 | - } |
|
| 155 | + } |
|
| 156 | 156 | |
| 157 | - /** |
|
| 157 | + /** |
|
| 158 | 158 | * Splits the string with the provided regular expression. |
| 159 | 159 | * |
| 160 | 160 | * @param string $pattern The regex with which to split the string. |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | */ |
| 170 | 170 | public function split($pattern, $limit = null, $quote = true) |
| 171 | 171 | { |
| 172 | - // Not sure why you would do this but your wish is our command :) |
|
| 172 | + // Not sure why you would do this but your wish is our command :) |
|
| 173 | 173 | if ($limit === 0) return []; |
| 174 | 174 | |
| 175 | 175 | // UTF8::split errors when supplied an empty pattern in < PHP 5.4.13 |
@@ -187,27 +187,27 @@ discard block |
||
| 187 | 187 | $limit = -1; |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | - // TODO: As per the above comments, all well and good but we are not |
|
| 191 | - // using UTF8::split here, we are using preg_split??? |
|
| 190 | + // TODO: As per the above comments, all well and good but we are not |
|
| 191 | + // using UTF8::split here, we are using preg_split??? |
|
| 192 | 192 | |
| 193 | - // Build the expression |
|
| 194 | - $expression = $this->regexDelimiter; |
|
| 193 | + // Build the expression |
|
| 194 | + $expression = $this->regexDelimiter; |
|
| 195 | 195 | |
| 196 | - if ($quote === true) |
|
| 197 | - { |
|
| 198 | - $expression .= preg_quote($pattern, $this->regexDelimiter); |
|
| 199 | - } |
|
| 200 | - else |
|
| 201 | - { |
|
| 202 | - $expression .= $pattern; |
|
| 203 | - } |
|
| 196 | + if ($quote === true) |
|
| 197 | + { |
|
| 198 | + $expression .= preg_quote($pattern, $this->regexDelimiter); |
|
| 199 | + } |
|
| 200 | + else |
|
| 201 | + { |
|
| 202 | + $expression .= $pattern; |
|
| 203 | + } |
|
| 204 | 204 | |
| 205 | - $expression .= $this->regexDelimiter.'u'; |
|
| 205 | + $expression .= $this->regexDelimiter.'u'; |
|
| 206 | 206 | |
| 207 | - // Split the string |
|
| 207 | + // Split the string |
|
| 208 | 208 | $array = preg_split($expression, $this->scalarString, $limit); |
| 209 | 209 | |
| 210 | - // Remove any remaining unsplit string. |
|
| 210 | + // Remove any remaining unsplit string. |
|
| 211 | 211 | if ($limit > 0 && count($array) === $limit) array_pop($array); |
| 212 | 212 | |
| 213 | 213 | return $this->newSelfs($array); |
@@ -53,7 +53,9 @@ discard block |
||
| 53 | 53 | public function regexMatch($pattern, $options = '') |
| 54 | 54 | { |
| 55 | 55 | // Ensure the options contain the "u" modifier. |
| 56 | - if (!$this->newSelf($options)->contains('u')) $options .= 'u'; |
|
| 56 | + if (!$this->newSelf($options)->contains('u')) { |
|
| 57 | + $options .= 'u'; |
|
| 58 | + } |
|
| 57 | 59 | |
| 58 | 60 | // Build the expression |
| 59 | 61 | $expression = |
@@ -67,7 +69,9 @@ discard block |
||
| 67 | 69 | $result = preg_match($expression, $this->scalarString); |
| 68 | 70 | |
| 69 | 71 | // If no errors return true or false based on number of matches found. |
| 70 | - if ($result !== false) return $result === 1; |
|
| 72 | + if ($result !== false) { |
|
| 73 | + return $result === 1; |
|
| 74 | + } |
|
| 71 | 75 | |
| 72 | 76 | // Otherwise throw with last known PCRE Error. |
| 73 | 77 | throw new PcreException(); |
@@ -94,7 +98,9 @@ discard block |
||
| 94 | 98 | $matches = []; |
| 95 | 99 | |
| 96 | 100 | // Ensure the options contain the "u" modifier. |
| 97 | - if (!$this->newSelf($options)->contains('u')) $options .= 'u'; |
|
| 101 | + if (!$this->newSelf($options)->contains('u')) { |
|
| 102 | + $options .= 'u'; |
|
| 103 | + } |
|
| 98 | 104 | |
| 99 | 105 | // Build the expression |
| 100 | 106 | $expression = |
@@ -108,7 +114,9 @@ discard block |
||
| 108 | 114 | $result = preg_match($expression, $this->scalarString, $matches); |
| 109 | 115 | |
| 110 | 116 | // If no errors return the $matches array |
| 111 | - if ($result !== false) return $this->newSelfs($matches); |
|
| 117 | + if ($result !== false) { |
|
| 118 | + return $this->newSelfs($matches); |
|
| 119 | + } |
|
| 112 | 120 | |
| 113 | 121 | // Otherwise throw with last known PCRE Error. |
| 114 | 122 | throw new PcreException(); |
@@ -131,10 +139,14 @@ discard block |
||
| 131 | 139 | { |
| 132 | 140 | // The original regexReplace method in danielstjules/Stringy used |
| 133 | 141 | // mb_ereg_replace() which supports an "r" flag, PCRE does not. |
| 134 | - if ($options === 'msr') $options = 'ms'; |
|
| 142 | + if ($options === 'msr') { |
|
| 143 | + $options = 'ms'; |
|
| 144 | + } |
|
| 135 | 145 | |
| 136 | 146 | // Ensure the options contain the "u" modifier. |
| 137 | - if (!$this->newSelf($options)->contains('u')) $options .= 'u'; |
|
| 147 | + if (!$this->newSelf($options)->contains('u')) { |
|
| 148 | + $options .= 'u'; |
|
| 149 | + } |
|
| 138 | 150 | |
| 139 | 151 | // Build the expression |
| 140 | 152 | $expression = |
@@ -148,7 +160,9 @@ discard block |
||
| 148 | 160 | $replaced = preg_replace($expression, $replacement, $this->scalarString); |
| 149 | 161 | |
| 150 | 162 | // If no errors return the replacement |
| 151 | - if ($replaced !== null) return $this->newSelf($replaced); |
|
| 163 | + if ($replaced !== null) { |
|
| 164 | + return $this->newSelf($replaced); |
|
| 165 | + } |
|
| 152 | 166 | |
| 153 | 167 | // Otherwise throw with last known PCRE Error. |
| 154 | 168 | throw new PcreException(); |
@@ -170,19 +184,22 @@ discard block |
||
| 170 | 184 | public function split($pattern, $limit = null, $quote = true) |
| 171 | 185 | { |
| 172 | 186 | // Not sure why you would do this but your wish is our command :) |
| 173 | - if ($limit === 0) return []; |
|
| 187 | + if ($limit === 0) { |
|
| 188 | + return []; |
|
| 189 | + } |
|
| 174 | 190 | |
| 175 | 191 | // UTF8::split errors when supplied an empty pattern in < PHP 5.4.13 |
| 176 | 192 | // and current versions of HHVM (3.8 and below) |
| 177 | - if ($pattern === '') return [$this->newSelf($this->scalarString)]; |
|
| 193 | + if ($pattern === '') { |
|
| 194 | + return [$this->newSelf($this->scalarString)]; |
|
| 195 | + } |
|
| 178 | 196 | |
| 179 | 197 | // UTF8::split returns the remaining unsplit string |
| 180 | 198 | // in the last index when supplying a limit. |
| 181 | 199 | if ($limit > 0) |
| 182 | 200 | { |
| 183 | 201 | $limit += 1; |
| 184 | - } |
|
| 185 | - else |
|
| 202 | + } else |
|
| 186 | 203 | { |
| 187 | 204 | $limit = -1; |
| 188 | 205 | } |
@@ -196,8 +213,7 @@ discard block |
||
| 196 | 213 | if ($quote === true) |
| 197 | 214 | { |
| 198 | 215 | $expression .= preg_quote($pattern, $this->regexDelimiter); |
| 199 | - } |
|
| 200 | - else |
|
| 216 | + } else |
|
| 201 | 217 | { |
| 202 | 218 | $expression .= $pattern; |
| 203 | 219 | } |
@@ -208,7 +224,9 @@ discard block |
||
| 208 | 224 | $array = preg_split($expression, $this->scalarString, $limit); |
| 209 | 225 | |
| 210 | 226 | // Remove any remaining unsplit string. |
| 211 | - if ($limit > 0 && count($array) === $limit) array_pop($array); |
|
| 227 | + if ($limit > 0 && count($array) === $limit) { |
|
| 228 | + array_pop($array); |
|
| 229 | + } |
|
| 212 | 230 | |
| 213 | 231 | return $this->newSelfs($array); |
| 214 | 232 | } |
@@ -16,46 +16,46 @@ |
||
| 16 | 16 | trait CaseManipulators |
| 17 | 17 | { |
| 18 | 18 | /** |
| 19 | - * Converts the first character of the string to lower case. |
|
| 20 | - * |
|
| 21 | - * @return static String with the first character of $str being lower case |
|
| 22 | - */ |
|
| 23 | - public function lowerCaseFirst() |
|
| 24 | - { |
|
| 25 | - $first = UTF8::substr($this->scalarString, 0, 1, $this->encoding); |
|
| 19 | + * Converts the first character of the string to lower case. |
|
| 20 | + * |
|
| 21 | + * @return static String with the first character of $str being lower case |
|
| 22 | + */ |
|
| 23 | + public function lowerCaseFirst() |
|
| 24 | + { |
|
| 25 | + $first = UTF8::substr($this->scalarString, 0, 1, $this->encoding); |
|
| 26 | 26 | |
| 27 | - $rest = UTF8::substr |
|
| 28 | - ( |
|
| 29 | - $this->scalarString, |
|
| 30 | - 1, |
|
| 31 | - $this->getLength() - 1, |
|
| 32 | - $this->encoding |
|
| 33 | - ); |
|
| 27 | + $rest = UTF8::substr |
|
| 28 | + ( |
|
| 29 | + $this->scalarString, |
|
| 30 | + 1, |
|
| 31 | + $this->getLength() - 1, |
|
| 32 | + $this->encoding |
|
| 33 | + ); |
|
| 34 | 34 | |
| 35 | - return $this->newSelf(UTF8::strtolower($first, $this->encoding).$rest); |
|
| 36 | - } |
|
| 35 | + return $this->newSelf(UTF8::strtolower($first, $this->encoding).$rest); |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Converts the first character of the supplied string to upper case. |
|
| 40 | - * |
|
| 41 | - * @return static String with the first character of $str being upper case |
|
| 42 | - */ |
|
| 43 | - public function upperCaseFirst() |
|
| 44 | - { |
|
| 45 | - $first = UTF8::substr($this->scalarString, 0, 1, $this->encoding); |
|
| 38 | + /** |
|
| 39 | + * Converts the first character of the supplied string to upper case. |
|
| 40 | + * |
|
| 41 | + * @return static String with the first character of $str being upper case |
|
| 42 | + */ |
|
| 43 | + public function upperCaseFirst() |
|
| 44 | + { |
|
| 45 | + $first = UTF8::substr($this->scalarString, 0, 1, $this->encoding); |
|
| 46 | 46 | |
| 47 | - $rest = UTF8::substr |
|
| 48 | - ( |
|
| 49 | - $this->scalarString, |
|
| 50 | - 1, |
|
| 51 | - $this->getLength() - 1, |
|
| 52 | - $this->encoding |
|
| 53 | - ); |
|
| 47 | + $rest = UTF8::substr |
|
| 48 | + ( |
|
| 49 | + $this->scalarString, |
|
| 50 | + 1, |
|
| 51 | + $this->getLength() - 1, |
|
| 52 | + $this->encoding |
|
| 53 | + ); |
|
| 54 | 54 | |
| 55 | - return $this->newSelf(UTF8::strtoupper($first, $this->encoding).$rest); |
|
| 56 | - } |
|
| 55 | + return $this->newSelf(UTF8::strtoupper($first, $this->encoding).$rest); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - /** |
|
| 58 | + /** |
|
| 59 | 59 | * Returns a case swapped version of the string. |
| 60 | 60 | * |
| 61 | 61 | * @return Stringy Object whose $str has each character's case swapped |
@@ -24,8 +24,7 @@ discard block |
||
| 24 | 24 | { |
| 25 | 25 | $first = UTF8::substr($this->scalarString, 0, 1, $this->encoding); |
| 26 | 26 | |
| 27 | - $rest = UTF8::substr |
|
| 28 | - ( |
|
| 27 | + $rest = UTF8::substr( |
|
| 29 | 28 | $this->scalarString, |
| 30 | 29 | 1, |
| 31 | 30 | $this->getLength() - 1, |
@@ -44,8 +43,7 @@ discard block |
||
| 44 | 43 | { |
| 45 | 44 | $first = UTF8::substr($this->scalarString, 0, 1, $this->encoding); |
| 46 | 45 | |
| 47 | - $rest = UTF8::substr |
|
| 48 | - ( |
|
| 46 | + $rest = UTF8::substr( |
|
| 49 | 47 | $this->scalarString, |
| 50 | 48 | 1, |
| 51 | 49 | $this->getLength() - 1, |
@@ -62,10 +60,9 @@ discard block |
||
| 62 | 60 | */ |
| 63 | 61 | public function swapCase() |
| 64 | 62 | { |
| 65 | - return $this->newSelf(preg_replace_callback |
|
| 66 | - ( |
|
| 63 | + return $this->newSelf(preg_replace_callback( |
|
| 67 | 64 | '/[\S]/u', |
| 68 | - function ($match) |
|
| 65 | + function($match) |
|
| 69 | 66 | { |
| 70 | 67 | $marchToUpper = UTF8::strtoupper($match[0], $this->encoding); |
| 71 | 68 | |
@@ -72,8 +72,7 @@ |
||
| 72 | 72 | if ($match[0] == $marchToUpper) |
| 73 | 73 | { |
| 74 | 74 | return UTF8::strtolower($match[0], $this->encoding); |
| 75 | - } |
|
| 76 | - else |
|
| 75 | + } else |
|
| 77 | 76 | { |
| 78 | 77 | return $marchToUpper; |
| 79 | 78 | } |
@@ -16,55 +16,55 @@ discard block |
||
| 16 | 16 | trait Html |
| 17 | 17 | { |
| 18 | 18 | /** |
| 19 | - * Convert all HTML entities to their applicable characters. |
|
| 20 | - * |
|
| 21 | - * @see http://php.net/manual/en/function.html-entity-decode.php |
|
| 22 | - * |
|
| 23 | - * @param int|null $flags Optional flags |
|
| 24 | - * |
|
| 25 | - * @return static String after being html decoded. |
|
| 26 | - */ |
|
| 27 | - public function htmlDecode($flags = ENT_COMPAT) |
|
| 28 | - { |
|
| 29 | - return $this->newSelf |
|
| 30 | - ( |
|
| 31 | - UTF8::html_entity_decode |
|
| 32 | - ( |
|
| 33 | - $this->scalarString, |
|
| 34 | - $flags, |
|
| 35 | - $this->encoding |
|
| 36 | - ) |
|
| 37 | - ); |
|
| 38 | - } |
|
| 19 | + * Convert all HTML entities to their applicable characters. |
|
| 20 | + * |
|
| 21 | + * @see http://php.net/manual/en/function.html-entity-decode.php |
|
| 22 | + * |
|
| 23 | + * @param int|null $flags Optional flags |
|
| 24 | + * |
|
| 25 | + * @return static String after being html decoded. |
|
| 26 | + */ |
|
| 27 | + public function htmlDecode($flags = ENT_COMPAT) |
|
| 28 | + { |
|
| 29 | + return $this->newSelf |
|
| 30 | + ( |
|
| 31 | + UTF8::html_entity_decode |
|
| 32 | + ( |
|
| 33 | + $this->scalarString, |
|
| 34 | + $flags, |
|
| 35 | + $this->encoding |
|
| 36 | + ) |
|
| 37 | + ); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Convert all applicable characters to HTML entities. |
|
| 42 | - * |
|
| 43 | - * @see http://php.net/manual/en/function.htmlentities.php |
|
| 44 | - * |
|
| 45 | - * @param int|null $flags Optional flags. |
|
| 46 | - * |
|
| 47 | - * @param bool $doubleEncode When double_encode is turned off PHP |
|
| 48 | - * will not encode existing html entities. |
|
| 49 | - * The default is to convert everything. |
|
| 50 | - * |
|
| 51 | - * @return static String after being html encoded. |
|
| 52 | - */ |
|
| 53 | - public function htmlEncode($flags = null, $doubleEncode = true) |
|
| 54 | - { |
|
| 55 | - if ($flags === null) $flags = ENT_QUOTES | ENT_SUBSTITUTE; |
|
| 40 | + /** |
|
| 41 | + * Convert all applicable characters to HTML entities. |
|
| 42 | + * |
|
| 43 | + * @see http://php.net/manual/en/function.htmlentities.php |
|
| 44 | + * |
|
| 45 | + * @param int|null $flags Optional flags. |
|
| 46 | + * |
|
| 47 | + * @param bool $doubleEncode When double_encode is turned off PHP |
|
| 48 | + * will not encode existing html entities. |
|
| 49 | + * The default is to convert everything. |
|
| 50 | + * |
|
| 51 | + * @return static String after being html encoded. |
|
| 52 | + */ |
|
| 53 | + public function htmlEncode($flags = null, $doubleEncode = true) |
|
| 54 | + { |
|
| 55 | + if ($flags === null) $flags = ENT_QUOTES | ENT_SUBSTITUTE; |
|
| 56 | 56 | |
| 57 | - return $this->newSelf |
|
| 58 | - ( |
|
| 59 | - UTF8::htmlentities |
|
| 60 | - ( |
|
| 61 | - $this->scalarString, |
|
| 62 | - $flags, |
|
| 63 | - $this->encoding, |
|
| 64 | - $doubleEncode |
|
| 65 | - ) |
|
| 66 | - ); |
|
| 67 | - } |
|
| 57 | + return $this->newSelf |
|
| 58 | + ( |
|
| 59 | + UTF8::htmlentities |
|
| 60 | + ( |
|
| 61 | + $this->scalarString, |
|
| 62 | + $flags, |
|
| 63 | + $this->encoding, |
|
| 64 | + $doubleEncode |
|
| 65 | + ) |
|
| 66 | + ); |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | 69 | /** |
| 70 | 70 | * Sanitizes data so that Cross Site Scripting Hacks can be prevented. |
@@ -87,25 +87,25 @@ discard block |
||
| 87 | 87 | */ |
| 88 | 88 | public function htmlXssClean() |
| 89 | 89 | { |
| 90 | - static $antiXss = null; |
|
| 90 | + static $antiXss = null; |
|
| 91 | 91 | |
| 92 | - if ($antiXss === null) |
|
| 93 | - { |
|
| 94 | - if (class_exists('\\voku\\helper\\AntiXSS')) |
|
| 95 | - { |
|
| 96 | - $antiXss = new \voku\helper\AntiXSS(); |
|
| 97 | - } |
|
| 98 | - else |
|
| 99 | - { |
|
| 100 | - throw new \RuntimeException |
|
| 101 | - ( |
|
| 102 | - "This method requires \voku\helper\AntiXSS. ". |
|
| 103 | - "Install with: composer require voku/anti-xss" |
|
| 104 | - ); |
|
| 105 | - } |
|
| 106 | - } |
|
| 92 | + if ($antiXss === null) |
|
| 93 | + { |
|
| 94 | + if (class_exists('\\voku\\helper\\AntiXSS')) |
|
| 95 | + { |
|
| 96 | + $antiXss = new \voku\helper\AntiXSS(); |
|
| 97 | + } |
|
| 98 | + else |
|
| 99 | + { |
|
| 100 | + throw new \RuntimeException |
|
| 101 | + ( |
|
| 102 | + "This method requires \voku\helper\AntiXSS. ". |
|
| 103 | + "Install with: composer require voku/anti-xss" |
|
| 104 | + ); |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - return $this->newSelf($antiXss->xss_clean($this->scalarString)); |
|
| 108 | + return $this->newSelf($antiXss->xss_clean($this->scalarString)); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | /** |
@@ -122,9 +122,9 @@ discard block |
||
| 122 | 122 | */ |
| 123 | 123 | public function htmlStripTags($allowableTags = null) |
| 124 | 124 | { |
| 125 | - return $this->newSelf |
|
| 126 | - ( |
|
| 127 | - UTF8::strip_tags($this->scalarString, $allowableTags) |
|
| 128 | - ); |
|
| 125 | + return $this->newSelf |
|
| 126 | + ( |
|
| 127 | + UTF8::strip_tags($this->scalarString, $allowableTags) |
|
| 128 | + ); |
|
| 129 | 129 | } |
| 130 | 130 | } |
@@ -26,10 +26,8 @@ discard block |
||
| 26 | 26 | */ |
| 27 | 27 | public function htmlDecode($flags = ENT_COMPAT) |
| 28 | 28 | { |
| 29 | - return $this->newSelf |
|
| 30 | - ( |
|
| 31 | - UTF8::html_entity_decode |
|
| 32 | - ( |
|
| 29 | + return $this->newSelf( |
|
| 30 | + UTF8::html_entity_decode( |
|
| 33 | 31 | $this->scalarString, |
| 34 | 32 | $flags, |
| 35 | 33 | $this->encoding |
@@ -54,10 +52,8 @@ discard block |
||
| 54 | 52 | { |
| 55 | 53 | if ($flags === null) $flags = ENT_QUOTES | ENT_SUBSTITUTE; |
| 56 | 54 | |
| 57 | - return $this->newSelf |
|
| 58 | - ( |
|
| 59 | - UTF8::htmlentities |
|
| 60 | - ( |
|
| 55 | + return $this->newSelf( |
|
| 56 | + UTF8::htmlentities( |
|
| 61 | 57 | $this->scalarString, |
| 62 | 58 | $flags, |
| 63 | 59 | $this->encoding, |
@@ -97,8 +93,7 @@ discard block |
||
| 97 | 93 | } |
| 98 | 94 | else |
| 99 | 95 | { |
| 100 | - throw new \RuntimeException |
|
| 101 | - ( |
|
| 96 | + throw new \RuntimeException( |
|
| 102 | 97 | "This method requires \voku\helper\AntiXSS. ". |
| 103 | 98 | "Install with: composer require voku/anti-xss" |
| 104 | 99 | ); |
@@ -122,8 +117,7 @@ discard block |
||
| 122 | 117 | */ |
| 123 | 118 | public function htmlStripTags($allowableTags = null) |
| 124 | 119 | { |
| 125 | - return $this->newSelf |
|
| 126 | - ( |
|
| 120 | + return $this->newSelf( |
|
| 127 | 121 | UTF8::strip_tags($this->scalarString, $allowableTags) |
| 128 | 122 | ); |
| 129 | 123 | } |
@@ -52,7 +52,9 @@ discard block |
||
| 52 | 52 | */ |
| 53 | 53 | public function htmlEncode($flags = null, $doubleEncode = true) |
| 54 | 54 | { |
| 55 | - if ($flags === null) $flags = ENT_QUOTES | ENT_SUBSTITUTE; |
|
| 55 | + if ($flags === null) { |
|
| 56 | + $flags = ENT_QUOTES | ENT_SUBSTITUTE; |
|
| 57 | + } |
|
| 56 | 58 | |
| 57 | 59 | return $this->newSelf |
| 58 | 60 | ( |
@@ -94,8 +96,7 @@ discard block |
||
| 94 | 96 | if (class_exists('\\voku\\helper\\AntiXSS')) |
| 95 | 97 | { |
| 96 | 98 | $antiXss = new \voku\helper\AntiXSS(); |
| 97 | - } |
|
| 98 | - else |
|
| 99 | + } else |
|
| 99 | 100 | { |
| 100 | 101 | throw new \RuntimeException |
| 101 | 102 | ( |