@@ -40,19 +40,19 @@ discard block |
||
| 40 | 40 | */ |
| 41 | 41 | class NumberInfo |
| 42 | 42 | { |
| 43 | - /** |
|
| 44 | - * @var string|int|float|null |
|
| 45 | - */ |
|
| 43 | + /** |
|
| 44 | + * @var string|int|float|null |
|
| 45 | + */ |
|
| 46 | 46 | protected $rawValue; |
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * @var array<string,mixed> |
|
| 50 | - */ |
|
| 48 | + /** |
|
| 49 | + * @var array<string,mixed> |
|
| 50 | + */ |
|
| 51 | 51 | protected $info; |
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * @var bool |
|
| 55 | - */ |
|
| 53 | + /** |
|
| 54 | + * @var bool |
|
| 55 | + */ |
|
| 56 | 56 | protected $empty = false; |
| 57 | 57 | |
| 58 | 58 | /** |
@@ -62,8 +62,8 @@ discard block |
||
| 62 | 62 | |
| 63 | 63 | /** |
| 64 | 64 | * Units and whether they allow decimal values. |
| 65 | - * @var array<string,bool> |
|
| 66 | - */ |
|
| 65 | + * @var array<string,bool> |
|
| 66 | + */ |
|
| 67 | 67 | protected $knownUnits = array( |
| 68 | 68 | '%' => true, |
| 69 | 69 | 'rem' => true, |
@@ -141,21 +141,21 @@ discard block |
||
| 141 | 141 | return $this; |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - /** |
|
| 145 | - * Retrieves the raw, internal information array resulting |
|
| 146 | - * from the parsing of the number. |
|
| 147 | - * |
|
| 148 | - * @return array<string,mixed> |
|
| 149 | - */ |
|
| 144 | + /** |
|
| 145 | + * Retrieves the raw, internal information array resulting |
|
| 146 | + * from the parsing of the number. |
|
| 147 | + * |
|
| 148 | + * @return array<string,mixed> |
|
| 149 | + */ |
|
| 150 | 150 | public function getRawInfo() : array |
| 151 | 151 | { |
| 152 | 152 | return $this->info; |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | - /** |
|
| 156 | - * Whether the number was empty (null or empty string). |
|
| 157 | - * @return boolean |
|
| 158 | - */ |
|
| 155 | + /** |
|
| 156 | + * Whether the number was empty (null or empty string). |
|
| 157 | + * @return boolean |
|
| 158 | + */ |
|
| 159 | 159 | public function isEmpty() : bool |
| 160 | 160 | { |
| 161 | 161 | return $this->empty; |
@@ -729,12 +729,12 @@ discard block |
||
| 729 | 729 | return $cache[$key]; |
| 730 | 730 | } |
| 731 | 731 | |
| 732 | - /** |
|
| 733 | - * Parses a string number notation with units included, e.g. 14px, 50%... |
|
| 734 | - * |
|
| 735 | - * @param string $test |
|
| 736 | - * @return array<string,mixed> |
|
| 737 | - */ |
|
| 732 | + /** |
|
| 733 | + * Parses a string number notation with units included, e.g. 14px, 50%... |
|
| 734 | + * |
|
| 735 | + * @param string $test |
|
| 736 | + * @return array<string,mixed> |
|
| 737 | + */ |
|
| 738 | 738 | private function parseStringValue(string $test) : array |
| 739 | 739 | { |
| 740 | 740 | $number = null; |
@@ -785,13 +785,13 @@ discard block |
||
| 785 | 785 | return $this->filterInfo($result); |
| 786 | 786 | } |
| 787 | 787 | |
| 788 | - /** |
|
| 789 | - * Attempts to determine what kind of units are specified |
|
| 790 | - * in the string. Returns NULL if none could be matched. |
|
| 791 | - * |
|
| 792 | - * @param string $value |
|
| 793 | - * @return array<string,mixed>|NULL |
|
| 794 | - */ |
|
| 788 | + /** |
|
| 789 | + * Attempts to determine what kind of units are specified |
|
| 790 | + * in the string. Returns NULL if none could be matched. |
|
| 791 | + * |
|
| 792 | + * @param string $value |
|
| 793 | + * @return array<string,mixed>|NULL |
|
| 794 | + */ |
|
| 795 | 795 | private function findUnits(string $value) : ?array |
| 796 | 796 | { |
| 797 | 797 | $vlength = strlen($value); |
@@ -819,12 +819,12 @@ discard block |
||
| 819 | 819 | return null; |
| 820 | 820 | } |
| 821 | 821 | |
| 822 | - /** |
|
| 823 | - * Creates the cache key for the specified value. |
|
| 824 | - * |
|
| 825 | - * @param mixed $value |
|
| 826 | - * @return string |
|
| 827 | - */ |
|
| 822 | + /** |
|
| 823 | + * Creates the cache key for the specified value. |
|
| 824 | + * |
|
| 825 | + * @param mixed $value |
|
| 826 | + * @return string |
|
| 827 | + */ |
|
| 828 | 828 | private function createValueKey($value) : string |
| 829 | 829 | { |
| 830 | 830 | if(!is_string($value) && !is_numeric($value)) |
@@ -835,59 +835,59 @@ discard block |
||
| 835 | 835 | return (string)$value; |
| 836 | 836 | } |
| 837 | 837 | |
| 838 | - /** |
|
| 839 | - * Called if explicitly enabled: allows filtering the |
|
| 840 | - * number after the detection process has completed. |
|
| 841 | - * |
|
| 842 | - * @param string|NULL $number The adjusted number |
|
| 843 | - * @param string $originalString The original value before it was parsed |
|
| 844 | - * @return string|null |
|
| 845 | - */ |
|
| 838 | + /** |
|
| 839 | + * Called if explicitly enabled: allows filtering the |
|
| 840 | + * number after the detection process has completed. |
|
| 841 | + * |
|
| 842 | + * @param string|NULL $number The adjusted number |
|
| 843 | + * @param string $originalString The original value before it was parsed |
|
| 844 | + * @return string|null |
|
| 845 | + */ |
|
| 846 | 846 | protected function postProcess(?string $number, /** @scrutinizer ignore-unused */ string $originalString) |
| 847 | 847 | { |
| 848 | 848 | return $number; |
| 849 | 849 | } |
| 850 | 850 | |
| 851 | - /** |
|
| 852 | - * Filters the value before it is parsed, but only if it is a string. |
|
| 853 | - * |
|
| 854 | - * NOTE: This may be overwritten in a subclass, to allow custom filtering |
|
| 855 | - * the values. An example of a use case would be a preprocessor for |
|
| 856 | - * variables in a templating system. |
|
| 857 | - * |
|
| 858 | - * @param string $trimmedString The trimmed value. |
|
| 859 | - * @param array<string,mixed> $cache The internal values cache array. |
|
| 860 | - * @param string $originalValue The original value that the NumberInfo was created for. |
|
| 861 | - * @return string |
|
| 862 | - * |
|
| 863 | - * @see NumberInfo::enablePostProcess() |
|
| 864 | - */ |
|
| 851 | + /** |
|
| 852 | + * Filters the value before it is parsed, but only if it is a string. |
|
| 853 | + * |
|
| 854 | + * NOTE: This may be overwritten in a subclass, to allow custom filtering |
|
| 855 | + * the values. An example of a use case would be a preprocessor for |
|
| 856 | + * variables in a templating system. |
|
| 857 | + * |
|
| 858 | + * @param string $trimmedString The trimmed value. |
|
| 859 | + * @param array<string,mixed> $cache The internal values cache array. |
|
| 860 | + * @param string $originalValue The original value that the NumberInfo was created for. |
|
| 861 | + * @return string |
|
| 862 | + * |
|
| 863 | + * @see NumberInfo::enablePostProcess() |
|
| 864 | + */ |
|
| 865 | 865 | protected function preProcess(string $trimmedString, /** @scrutinizer ignore-unused */ array &$cache, /** @scrutinizer ignore-unused */ string $originalValue) : string |
| 866 | 866 | { |
| 867 | 867 | return str_replace(',', '.', $trimmedString); |
| 868 | 868 | } |
| 869 | 869 | |
| 870 | - /** |
|
| 871 | - * Enables the post-processing so the postProcess method gets called. |
|
| 872 | - * This should be called in the {@link NumberInfo::preProcess()} |
|
| 873 | - * method as needed. |
|
| 874 | - * |
|
| 875 | - * @return $this |
|
| 876 | - * @see NumberInfo::postProcess() |
|
| 877 | - */ |
|
| 870 | + /** |
|
| 871 | + * Enables the post-processing so the postProcess method gets called. |
|
| 872 | + * This should be called in the {@link NumberInfo::preProcess()} |
|
| 873 | + * method as needed. |
|
| 874 | + * |
|
| 875 | + * @return $this |
|
| 876 | + * @see NumberInfo::postProcess() |
|
| 877 | + */ |
|
| 878 | 878 | protected function enablePostProcess() : NumberInfo |
| 879 | 879 | { |
| 880 | 880 | $this->postProcess = true; |
| 881 | 881 | return $this; |
| 882 | 882 | } |
| 883 | 883 | |
| 884 | - /** |
|
| 885 | - * Filters the number info array to adjust the units |
|
| 886 | - * and number according to the required rules. |
|
| 887 | - * |
|
| 888 | - * @param array<string,mixed> $info |
|
| 889 | - * @return array<string,mixed> |
|
| 890 | - */ |
|
| 884 | + /** |
|
| 885 | + * Filters the number info array to adjust the units |
|
| 886 | + * and number according to the required rules. |
|
| 887 | + * |
|
| 888 | + * @param array<string,mixed> $info |
|
| 889 | + * @return array<string,mixed> |
|
| 890 | + */ |
|
| 891 | 891 | protected function filterInfo(array $info) : array |
| 892 | 892 | { |
| 893 | 893 | $useUnits = 'px'; |