@@ -14,24 +14,29 @@ |
||
| 14 | 14 | { |
| 15 | 15 | public function __invoke($array, $key, $order = 'ASC', $case_insensitive = false) |
| 16 | 16 | { |
| 17 | - if (!is_array($array)) { |
|
| 17 | + if (!is_array($array)) |
|
| 18 | + { |
|
| 18 | 19 | return $array; |
| 19 | 20 | } |
| 20 | 21 | |
| 21 | - usort($array, function ($a, $b) use ($key, $order, $case_insensitive) { |
|
| 22 | + usort($array, function ($a, $b) use ($key, $order, $case_insensitive) |
|
| 23 | + { |
|
| 22 | 24 | $aValue = __::get($a, $key); |
| 23 | 25 | $bValue = __::get($b, $key); |
| 24 | 26 | |
| 25 | - if ($case_insensitive) { |
|
| 27 | + if ($case_insensitive) |
|
| 28 | + { |
|
| 26 | 29 | $aValue = strtolower($aValue); |
| 27 | 30 | $bValue = strtolower($bValue); |
| 28 | 31 | } |
| 29 | 32 | |
| 30 | - if ($aValue == $bValue) { |
|
| 33 | + if ($aValue == $bValue) |
|
| 34 | + { |
|
| 31 | 35 | return 0; |
| 32 | 36 | } |
| 33 | 37 | |
| 34 | - if (strtolower((string)$order) === 'desc') { |
|
| 38 | + if (strtolower((string)$order) === 'desc') |
|
| 39 | + { |
|
| 35 | 40 | return ($aValue < $bValue) ? 1 : -1; |
| 36 | 41 | } |
| 37 | 42 | |
@@ -16,19 +16,23 @@ |
||
| 16 | 16 | { |
| 17 | 17 | $results = []; |
| 18 | 18 | |
| 19 | - foreach ($array as $item) { |
|
| 19 | + foreach ($array as $item) |
|
| 20 | + { |
|
| 20 | 21 | $results[] = __::get($item, $key); |
| 21 | 22 | } |
| 22 | 23 | |
| 23 | - if ($flatten) { |
|
| 24 | + if ($flatten) |
|
| 25 | + { |
|
| 24 | 26 | $results = __::flatten($results); |
| 25 | 27 | |
| 26 | - if ($distinct) { |
|
| 28 | + if ($distinct) |
|
| 29 | + { |
|
| 27 | 30 | $results = array_values(array_unique($results)); |
| 28 | 31 | } |
| 29 | 32 | } |
| 30 | 33 | |
| 31 | - if ($ignore_null) { |
|
| 34 | + if ($ignore_null) |
|
| 35 | + { |
|
| 32 | 36 | $results = array_values(array_filter($results)); |
| 33 | 37 | } |
| 34 | 38 | |
@@ -15,7 +15,8 @@ discard block |
||
| 15 | 15 | { |
| 16 | 16 | public function __invoke($value, $paragraphCount = 1) |
| 17 | 17 | { |
| 18 | - if (!extension_loaded('dom')) { |
|
| 18 | + if (!extension_loaded('dom')) |
|
| 19 | + { |
|
| 19 | 20 | @trigger_error('The DOM Extension is not loaded and is necessary for the "summary" Twig filter.', E_WARNING); |
| 20 | 21 | |
| 21 | 22 | return $value; |
@@ -26,7 +27,8 @@ discard block |
||
| 26 | 27 | |
| 27 | 28 | $summary = ''; |
| 28 | 29 | |
| 29 | - foreach ($paragraphs as $paragraph) { |
|
| 30 | + foreach ($paragraphs as $paragraph) |
|
| 31 | + { |
|
| 30 | 32 | $summary .= $dom->saveHTML($paragraph); |
| 31 | 33 | } |
| 32 | 34 | |
@@ -17,20 +17,24 @@ discard block |
||
| 17 | 17 | $arr1_length = count($array1); |
| 18 | 18 | $arr2_length = count($array2); |
| 19 | 19 | |
| 20 | - for ($i = 0; $i < $arr1_length; ++$i) { |
|
| 21 | - if ($i >= $arr2_length) { |
|
| 20 | + for ($i = 0; $i < $arr1_length; ++$i) |
|
| 21 | + { |
|
| 22 | + if ($i >= $arr2_length) |
|
| 23 | + { |
|
| 22 | 24 | break; |
| 23 | 25 | } |
| 24 | 26 | |
| 25 | 27 | $rhs = self::safe_get($array1, $i); |
| 26 | 28 | $lhs = self::safe_get($array2, $i); |
| 27 | 29 | |
| 28 | - if (empty($rhs)) { |
|
| 30 | + if (empty($rhs)) |
|
| 31 | + { |
|
| 29 | 32 | $result[] = $lhs; |
| 30 | 33 | |
| 31 | 34 | continue; |
| 32 | 35 | } |
| 33 | - if (empty($lhs)) { |
|
| 36 | + if (empty($lhs)) |
|
| 37 | + { |
|
| 34 | 38 | $result[] = $rhs; |
| 35 | 39 | |
| 36 | 40 | continue; |
@@ -39,10 +43,14 @@ discard block |
||
| 39 | 43 | $result[] = self::safe_get($array1, $i) . $glue . self::safe_get($array2, $i); |
| 40 | 44 | } |
| 41 | 45 | |
| 42 | - if (!$strict) { |
|
| 43 | - if ($arr2_length > $arr1_length) { |
|
| 46 | + if (!$strict) |
|
| 47 | + { |
|
| 48 | + if ($arr2_length > $arr1_length) |
|
| 49 | + { |
|
| 44 | 50 | $result = array_merge($result, array_slice($array2, $arr1_length)); |
| 45 | - } else { |
|
| 51 | + } |
|
| 52 | + else |
|
| 53 | + { |
|
| 46 | 54 | $result = array_merge($result, array_slice($array1, $arr2_length)); |
| 47 | 55 | } |
| 48 | 56 | } |
@@ -30,8 +30,10 @@ |
||
| 30 | 30 | $pieces = mb_split((string)$separator, (string)$value); |
| 31 | 31 | mb_regex_encoding($previous); |
| 32 | 32 | |
| 33 | - foreach ($pieces as $piece) { |
|
| 34 | - while (!$preserve && mb_strlen((string)$piece, $env->getCharset()) > $length) { |
|
| 33 | + foreach ($pieces as $piece) |
|
| 34 | + { |
|
| 35 | + while (!$preserve && mb_strlen((string)$piece, $env->getCharset()) > $length) |
|
| 36 | + { |
|
| 35 | 37 | $sentences[] = mb_substr((string)$piece, 0, $length, $env->getCharset()); |
| 36 | 38 | $piece = mb_substr((string)$piece, $length, 2048, $env->getCharset()); |
| 37 | 39 | } |
@@ -16,16 +16,21 @@ |
||
| 16 | 16 | { |
| 17 | 17 | $arr = []; |
| 18 | 18 | |
| 19 | - foreach ($array as $key => $item) { |
|
| 19 | + foreach ($array as $key => $item) |
|
| 20 | + { |
|
| 20 | 21 | $groupBy = __::get($item, $sortKey); |
| 21 | 22 | |
| 22 | - if ($groupBy === null) { |
|
| 23 | + if ($groupBy === null) |
|
| 24 | + { |
|
| 23 | 25 | continue; |
| 24 | 26 | } |
| 25 | 27 | |
| 26 | - if (is_bool($groupBy)) { |
|
| 28 | + if (is_bool($groupBy)) |
|
| 29 | + { |
|
| 27 | 30 | $groupBy = $groupBy ? 'true' : 'false'; |
| 28 | - } elseif (!is_scalar($groupBy)) { |
|
| 31 | + } |
|
| 32 | + elseif (!is_scalar($groupBy)) |
|
| 33 | + { |
|
| 29 | 34 | trigger_error('You cannot group by a non-scalar value', E_USER_WARNING); |
| 30 | 35 | |
| 31 | 36 | continue; |
@@ -22,10 +22,13 @@ |
||
| 22 | 22 | { |
| 23 | 23 | public function __invoke(Twig_Environment $env, $value, $length = 30, $preserve = false, $separator = '...') |
| 24 | 24 | { |
| 25 | - if (mb_strlen((string)$value, $env->getCharset()) > $length) { |
|
| 26 | - if ($preserve) { |
|
| 25 | + if (mb_strlen((string)$value, $env->getCharset()) > $length) |
|
| 26 | + { |
|
| 27 | + if ($preserve) |
|
| 28 | + { |
|
| 27 | 29 | // If breakpoint is on the last word, return the value without separator. |
| 28 | - if (($breakpoint = mb_strpos((string)$value, ' ', $length, $env->getCharset())) === false) { |
|
| 30 | + if (($breakpoint = mb_strpos((string)$value, ' ', $length, $env->getCharset())) === false) |
|
| 31 | + { |
|
| 29 | 32 | return $value; |
| 30 | 33 | } |
| 31 | 34 | |
@@ -21,7 +21,8 @@ discard block |
||
| 21 | 21 | |
| 22 | 22 | public function __invoke(Environment $env, $assetPath, $absolute = false, $params = []): string |
| 23 | 23 | { |
| 24 | - if ($this->isExternalUrl($assetPath)) { |
|
| 24 | + if ($this->isExternalUrl($assetPath)) |
|
| 25 | + { |
|
| 25 | 26 | return $assetPath; |
| 26 | 27 | } |
| 27 | 28 | |
@@ -46,11 +47,13 @@ discard block |
||
| 46 | 47 | { |
| 47 | 48 | $url = '/'; |
| 48 | 49 | |
| 49 | - if (!$absolute) { |
|
| 50 | + if (!$absolute) |
|
| 51 | + { |
|
| 50 | 52 | return $url; |
| 51 | 53 | } |
| 52 | 54 | |
| 53 | - if (isset($this->site['url'])) { |
|
| 55 | + if (isset($this->site['url'])) |
|
| 56 | + { |
|
| 54 | 57 | $url = $this->site['url']; |
| 55 | 58 | } |
| 56 | 59 | |
@@ -61,9 +64,12 @@ discard block |
||
| 61 | 64 | { |
| 62 | 65 | $base = ''; |
| 63 | 66 | |
| 64 | - if (isset($this->site['baseurl'])) { |
|
| 67 | + if (isset($this->site['baseurl'])) |
|
| 68 | + { |
|
| 65 | 69 | $base = $this->site['baseurl']; |
| 66 | - } elseif (isset($this->site['base'])) { |
|
| 70 | + } |
|
| 71 | + elseif (isset($this->site['base'])) |
|
| 72 | + { |
|
| 67 | 73 | $base = $this->site['base']; |
| 68 | 74 | } |
| 69 | 75 | |
@@ -72,16 +78,20 @@ discard block |
||
| 72 | 78 | |
| 73 | 79 | private function guessAssetPath($assetPath, $params): string |
| 74 | 80 | { |
| 75 | - if ($assetPath instanceof JailedDocument && $assetPath->_coreInstanceOf(RepeaterPageView::class)) { |
|
| 81 | + if ($assetPath instanceof JailedDocument && $assetPath->_coreInstanceOf(RepeaterPageView::class)) |
|
| 82 | + { |
|
| 76 | 83 | return ($link = $assetPath->_getPermalinkWhere($params)) ? $link : '/'; |
| 77 | 84 | } |
| 78 | - if (is_array($assetPath) || ($assetPath instanceof ArrayAccess)) { |
|
| 85 | + if (is_array($assetPath) || ($assetPath instanceof ArrayAccess)) |
|
| 86 | + { |
|
| 79 | 87 | return $assetPath['permalink'] ?? '/'; |
| 80 | 88 | } |
| 81 | - if (is_null($assetPath)) { |
|
| 89 | + if (is_null($assetPath)) |
|
| 90 | + { |
|
| 82 | 91 | return '/'; |
| 83 | 92 | } |
| 84 | - if ($assetPath instanceof SplFileInfo) { |
|
| 93 | + if ($assetPath instanceof SplFileInfo) |
|
| 94 | + { |
|
| 85 | 95 | return str_replace(Service::getWorkingDirectory(), '', $assetPath); |
| 86 | 96 | } |
| 87 | 97 | |
@@ -99,7 +109,8 @@ discard block |
||
| 99 | 109 | */ |
| 100 | 110 | private function isExternalUrl(mixed $str): bool |
| 101 | 111 | { |
| 102 | - if (!is_string($str)) { |
|
| 112 | + if (!is_string($str)) |
|
| 113 | + { |
|
| 103 | 114 | return false; |
| 104 | 115 | } |
| 105 | 116 | |
@@ -113,8 +124,10 @@ discard block |
||
| 113 | 124 | { |
| 114 | 125 | $paths = []; |
| 115 | 126 | |
| 116 | - foreach (func_get_args() as $arg) { |
|
| 117 | - if ($arg !== '') { |
|
| 127 | + foreach (func_get_args() as $arg) |
|
| 128 | + { |
|
| 129 | + if ($arg !== '') |
|
| 130 | + { |
|
| 118 | 131 | $paths[] = $arg; |
| 119 | 132 | } |
| 120 | 133 | } |
@@ -45,8 +45,10 @@ discard block |
||
| 45 | 45 | { |
| 46 | 46 | $results = []; |
| 47 | 47 | |
| 48 | - foreach ($array as $item) { |
|
| 49 | - if ($this->compare($item, $key, $comparison, $value)) { |
|
| 48 | + foreach ($array as $item) |
|
| 49 | + { |
|
| 50 | + if ($this->compare($item, $key, $comparison, $value)) |
|
| 51 | + { |
|
| 50 | 52 | $results[] = $item; |
| 51 | 53 | } |
| 52 | 54 | } |
@@ -71,13 +73,15 @@ discard block |
||
| 71 | 73 | */ |
| 72 | 74 | private function compare(mixed $item, string $key, string $comparison, mixed $value): bool |
| 73 | 75 | { |
| 74 | - if ($this->compareNullValues($item, $key, $comparison, $value)) { |
|
| 76 | + if ($this->compareNullValues($item, $key, $comparison, $value)) |
|
| 77 | + { |
|
| 75 | 78 | return true; |
| 76 | 79 | } |
| 77 | 80 | |
| 78 | 81 | $lhsValue = __::get($item, $key); |
| 79 | 82 | |
| 80 | - if ($lhsValue === null) { |
|
| 83 | + if ($lhsValue === null) |
|
| 84 | + { |
|
| 81 | 85 | return false; |
| 82 | 86 | } |
| 83 | 87 | |
@@ -94,15 +98,19 @@ discard block |
||
| 94 | 98 | */ |
| 95 | 99 | private function compareNullValues($item, $key, $operator, mixed $value): bool |
| 96 | 100 | { |
| 97 | - if ($operator !== '==' && $operator !== '!=') { |
|
| 101 | + if ($operator !== '==' && $operator !== '!=') |
|
| 102 | + { |
|
| 98 | 103 | return false; |
| 99 | 104 | } |
| 100 | 105 | |
| 101 | - if (!__::has($item, $key)) { |
|
| 102 | - if ($operator === '==' && $value === null) { |
|
| 106 | + if (!__::has($item, $key)) |
|
| 107 | + { |
|
| 108 | + if ($operator === '==' && $value === null) |
|
| 109 | + { |
|
| 103 | 110 | return true; |
| 104 | 111 | } |
| 105 | - if ($operator === '!=' && $value !== null) { |
|
| 112 | + if ($operator === '!=' && $value !== null) |
|
| 113 | + { |
|
| 106 | 114 | return true; |
| 107 | 115 | } |
| 108 | 116 | } |
@@ -138,7 +146,8 @@ discard block |
||
| 138 | 146 | |
| 139 | 147 | private function containsCaseInsensitive($haystack, $needle): bool |
| 140 | 148 | { |
| 141 | - if (is_array($haystack)) { |
|
| 149 | + if (is_array($haystack)) |
|
| 150 | + { |
|
| 142 | 151 | $downCase = array_combine(array_map('strtolower', $haystack), $haystack); |
| 143 | 152 | |
| 144 | 153 | return isset($downCase[strtolower((string)$needle)]); |