Complex classes like FunctionRegistry often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use FunctionRegistry, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 36 | class FunctionRegistry |
||
| 37 | { |
||
| 38 | /** |
||
| 39 | * Maximum allowed size of data uri for IE8. |
||
| 40 | */ |
||
| 41 | const IE8_DATA_URI_MAX = 32768; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Less environment. |
||
| 45 | * |
||
| 46 | * @var Context |
||
| 47 | */ |
||
| 48 | protected $context; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Array of function aliases. |
||
| 52 | * |
||
| 53 | * @var array |
||
| 54 | */ |
||
| 55 | protected $aliases = [ |
||
| 56 | '%' => 'template', |
||
| 57 | 'data-uri' => 'dataUri', |
||
| 58 | 'get-unit' => 'getunit', |
||
| 59 | 'svg-gradient' => 'svggradient', |
||
| 60 | 'default' => 'defaultFunc', |
||
| 61 | 'image-size' => 'imageSize', |
||
| 62 | 'image-width' => 'imageWidth', |
||
| 63 | 'image-height' => 'imageHeight', |
||
| 64 | ]; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @var FileInfo |
||
| 68 | */ |
||
| 69 | protected $currentFileInfo; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @var FunctionRegistry |
||
| 73 | */ |
||
| 74 | private $parent; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Array of callable functions. |
||
| 78 | * |
||
| 79 | * @var array |
||
| 80 | */ |
||
| 81 | private $functions = [ |
||
| 82 | 'abs' => true, |
||
| 83 | 'acos' => true, |
||
| 84 | 'alpha' => true, |
||
| 85 | 'argb' => true, |
||
| 86 | 'asin' => true, |
||
| 87 | 'atan' => true, |
||
| 88 | 'average' => true, |
||
| 89 | 'blue' => true, |
||
| 90 | 'call' => true, |
||
| 91 | 'ceil' => true, |
||
| 92 | 'clamp' => true, |
||
| 93 | 'color' => true, |
||
| 94 | 'contrast' => true, |
||
| 95 | 'convert' => true, |
||
| 96 | 'cos' => true, |
||
| 97 | 'darken' => true, |
||
| 98 | 'dataUri' => true, |
||
| 99 | 'desaturate' => true, |
||
| 100 | 'difference' => true, |
||
| 101 | 'e' => true, |
||
| 102 | 'escape' => true, |
||
| 103 | 'exclusion' => true, |
||
| 104 | 'extract' => true, |
||
| 105 | 'fade' => true, |
||
| 106 | 'fadein' => true, |
||
| 107 | 'fadeout' => true, |
||
| 108 | 'floor' => true, |
||
| 109 | 'green' => true, |
||
| 110 | 'greyscale' => true, |
||
| 111 | 'hardlight' => true, |
||
| 112 | 'hsl' => true, |
||
| 113 | 'hsla' => true, |
||
| 114 | 'hsv' => true, |
||
| 115 | 'hsva' => true, |
||
| 116 | 'hsvhue' => true, |
||
| 117 | 'hsvsaturation' => true, |
||
| 118 | 'hsvvalue' => true, |
||
| 119 | 'hue' => true, |
||
| 120 | 'iscolor' => true, |
||
| 121 | 'isem' => true, |
||
| 122 | 'iskeyword' => true, |
||
| 123 | 'isnumber' => true, |
||
| 124 | 'ispercentage' => true, |
||
| 125 | 'ispixel' => true, |
||
| 126 | 'isstring' => true, |
||
| 127 | 'isunit' => true, |
||
| 128 | 'isurl' => true, |
||
| 129 | 'isruleset' => true, |
||
| 130 | 'length' => true, |
||
| 131 | 'lighten' => true, |
||
| 132 | 'lightness' => true, |
||
| 133 | 'luma' => true, |
||
| 134 | 'luminance' => true, |
||
| 135 | 'max' => true, |
||
| 136 | 'min' => true, |
||
| 137 | 'mix' => true, |
||
| 138 | 'mod' => true, |
||
| 139 | 'multiply' => true, |
||
| 140 | 'negation' => true, |
||
| 141 | 'number' => true, |
||
| 142 | 'overlay' => true, |
||
| 143 | 'percentage' => true, |
||
| 144 | 'pi' => true, |
||
| 145 | 'pow' => true, |
||
| 146 | 'red' => true, |
||
| 147 | 'replace' => true, |
||
| 148 | 'rgb' => true, |
||
| 149 | 'rgba' => true, |
||
| 150 | 'round' => true, |
||
| 151 | 'saturate' => true, |
||
| 152 | 'saturation' => true, |
||
| 153 | 'screen' => true, |
||
| 154 | 'shade' => true, |
||
| 155 | 'sin' => true, |
||
| 156 | 'softlight' => true, |
||
| 157 | 'spin' => true, |
||
| 158 | 'sqrt' => true, |
||
| 159 | 'svggradient' => true, |
||
| 160 | 'tan' => true, |
||
| 161 | 'template' => true, |
||
| 162 | 'tint' => true, |
||
| 163 | 'unit' => true, |
||
| 164 | 'getunit' => true, |
||
| 165 | 'defaultFunc' => true, |
||
| 166 | 'imageSize' => true, |
||
| 167 | 'imageWidth' => true, |
||
| 168 | 'imageHeight' => true, |
||
| 169 | ]; |
||
| 170 | |||
| 171 | /** |
||
| 172 | * Constructor. |
||
| 173 | * |
||
| 174 | * @param array $aliases Array of function aliases in the format array(alias => function) |
||
| 175 | * @param Context $context The context |
||
| 176 | */ |
||
| 177 | public function __construct($aliases = [], Context $context = null) |
||
| 182 | |||
| 183 | /** |
||
| 184 | * @param FileInfo $file |
||
| 185 | * |
||
| 186 | * @return $this |
||
| 187 | */ |
||
| 188 | public function setCurrentFile(FileInfo $file) |
||
| 194 | |||
| 195 | /** |
||
| 196 | * Adds a function to the functions. |
||
| 197 | * |
||
| 198 | * @param string $functionName |
||
| 199 | * @param callable $callable |
||
| 200 | * @param string|array $aliases The array of aliases |
||
| 201 | * |
||
| 202 | * @return FunctionRegistry |
||
| 203 | * |
||
| 204 | * @throws InvalidArgumentException If the callable is not valid |
||
| 205 | */ |
||
| 206 | public function addFunction($functionName, $callable, $aliases = []) |
||
| 229 | |||
| 230 | /** |
||
| 231 | * Adds functions. |
||
| 232 | * |
||
| 233 | * <pre> |
||
| 234 | * $registry->addFunctions(array('name' => function() {})); |
||
| 235 | * $registry->addFunctions(array(array('name' => 'load', 'callable' => 'load')); |
||
| 236 | * $registry->addFunctions(array(array('name' => 'load', 'callable' => 'load', 'alias' => 'l')); |
||
| 237 | * </pre> |
||
| 238 | * |
||
| 239 | * @param array $functions Array of functions |
||
| 240 | * |
||
| 241 | * @return FunctionRegistry |
||
| 242 | */ |
||
| 243 | public function addFunctions(array $functions) |
||
| 260 | |||
| 261 | /** |
||
| 262 | * Sets the parent registry. |
||
| 263 | * |
||
| 264 | * @param FunctionRegistry $parent |
||
| 265 | * |
||
| 266 | * @return $this |
||
| 267 | */ |
||
| 268 | public function setParent(FunctionRegistry $parent) |
||
| 279 | |||
| 280 | /** |
||
| 281 | * Loads a plugin from given path. |
||
| 282 | * |
||
| 283 | * @param string $path |
||
| 284 | * |
||
| 285 | * @return $this |
||
| 286 | * |
||
| 287 | * @throws RuntimeException |
||
| 288 | */ |
||
| 289 | public function loadPlugin($path) |
||
| 303 | |||
| 304 | /** |
||
| 305 | * Clones the registry and setups the parent. |
||
| 306 | * |
||
| 307 | * @return FunctionRegistry |
||
| 308 | */ |
||
| 309 | public function inherit() |
||
| 317 | |||
| 318 | /** |
||
| 319 | * Returns names of registered functions. |
||
| 320 | * |
||
| 321 | * @return array |
||
| 322 | */ |
||
| 323 | public function getFunctions() |
||
| 327 | |||
| 328 | /** |
||
| 329 | * Does the function exist? |
||
| 330 | * |
||
| 331 | * @param string $name |
||
| 332 | * |
||
| 333 | * @return bool |
||
| 334 | */ |
||
| 335 | public function hasFunction($name) |
||
| 341 | |||
| 342 | /** |
||
| 343 | * Returns aliases for registered functions. |
||
| 344 | * |
||
| 345 | * @param bool $withFunctions Include function names? |
||
| 346 | * |
||
| 347 | * @return array |
||
| 348 | */ |
||
| 349 | public function getAliases($withFunctions = false) |
||
| 353 | |||
| 354 | /** |
||
| 355 | * Adds a function alias. |
||
| 356 | * |
||
| 357 | * @param string $alias The alias name |
||
| 358 | * @param string $function The function name |
||
| 359 | * |
||
| 360 | * @return FunctionRegistry |
||
| 361 | */ |
||
| 362 | public function addAlias($alias, $function) |
||
| 374 | |||
| 375 | /** |
||
| 376 | * Adds aliases. |
||
| 377 | * |
||
| 378 | * @param array $aliases |
||
| 379 | * |
||
| 380 | * @return FunctionRegistry |
||
| 381 | */ |
||
| 382 | public function addAliases(array $aliases) |
||
| 390 | |||
| 391 | /** |
||
| 392 | * Sets The context. |
||
| 393 | * |
||
| 394 | * @param Context $context |
||
| 395 | */ |
||
| 396 | public function setEnvironment(Context $context) |
||
| 400 | |||
| 401 | /** |
||
| 402 | * Returns the context instance. |
||
| 403 | * |
||
| 404 | * @return mixed |
||
| 405 | */ |
||
| 406 | public function getContext() |
||
| 410 | |||
| 411 | /** |
||
| 412 | * Calls a method with given arguments. |
||
| 413 | * |
||
| 414 | * @param string $methodName |
||
| 415 | * @param array $arguments |
||
| 416 | * |
||
| 417 | * @return mixed |
||
| 418 | * |
||
| 419 | * @throws FunctionException If the method does not exist |
||
| 420 | */ |
||
| 421 | public function call($methodName, $arguments = []) |
||
| 448 | |||
| 449 | /** |
||
| 450 | * Prepares the arguments before function calls. |
||
| 451 | * This does the same as in less.js's functionCaller object. |
||
| 452 | * |
||
| 453 | * @param array $arguments |
||
| 454 | * |
||
| 455 | * @return array |
||
| 456 | */ |
||
| 457 | protected function prepareArguments(array $arguments) |
||
| 497 | |||
| 498 | /** |
||
| 499 | * Applies URL-encoding to special characters found in the input string. |
||
| 500 | * |
||
| 501 | * * Following characters are exceptions and not encoded: `,, /, ?, @, &, +, ', ~, ! $` |
||
| 502 | * * Most common encoded characters are: `<space>`, #, ^, (, ), {, }, |, :, >, <, ;, ], [ =` |
||
| 503 | * |
||
| 504 | * @param Node $string A string to escape |
||
| 505 | * |
||
| 506 | * @return AnonymousNode Escaped string content without quotes. |
||
| 507 | */ |
||
| 508 | public function escape(Node $string) |
||
| 512 | |||
| 513 | /** |
||
| 514 | * CSS escaping similar to ~"value" syntax. It expects string as a parameter and return |
||
| 515 | * its content as is, but without quotes. It can be used to output CSS value which is either not valid CSS syntax, |
||
| 516 | * or uses proprietary syntax which LESS doesn't recognize. |
||
| 517 | * |
||
| 518 | * @param string $string A string to escape |
||
| 519 | * |
||
| 520 | * @return AnonymousNode Content without quotes. |
||
| 521 | */ |
||
| 522 | public function e(Node $string) |
||
| 526 | |||
| 527 | /** |
||
| 528 | * Returns the number of items. |
||
| 529 | * |
||
| 530 | * @param Node $values |
||
| 531 | * |
||
| 532 | * @return DimensionNode |
||
| 533 | */ |
||
| 534 | public function length(Node $values) |
||
| 538 | |||
| 539 | /** |
||
| 540 | * Min. |
||
| 541 | * |
||
| 542 | * @return DimensionNode |
||
| 543 | */ |
||
| 544 | public function min() |
||
| 548 | |||
| 549 | /** |
||
| 550 | * Max. |
||
| 551 | * |
||
| 552 | * @return DimensionNode |
||
| 553 | */ |
||
| 554 | public function max() |
||
| 558 | |||
| 559 | /** |
||
| 560 | * Extract. |
||
| 561 | * |
||
| 562 | * @param Node $node |
||
| 563 | * @param Node $index |
||
| 564 | * |
||
| 565 | * @return null|Node |
||
| 566 | */ |
||
| 567 | public function extract(Node $node, Node $index) |
||
| 577 | |||
| 578 | /** |
||
| 579 | * @param Node $node |
||
| 580 | * |
||
| 581 | * @return array |
||
| 582 | */ |
||
| 583 | private function getItemsFromNode(Node $node) |
||
| 596 | |||
| 597 | /** |
||
| 598 | * Formats a string. Less equivalent is: `%`. |
||
| 599 | * The first argument is string with placeholders. |
||
| 600 | * All placeholders start with percentage symbol % followed by letter s,S,d,D,a, or A. |
||
| 601 | * Remaining arguments contain expressions to replace placeholders. |
||
| 602 | * If you need to print the percentage symbol, escape it by another percentage %%.*. |
||
| 603 | * |
||
| 604 | * @param Node $string |
||
| 605 | * |
||
| 606 | * @return QuotedNode |
||
| 607 | */ |
||
| 608 | public function template(Node $string /* , $value1, $value2, ... */) |
||
| 636 | |||
| 637 | /** |
||
| 638 | * Replaces a string or regexp pattern within a string. |
||
| 639 | * |
||
| 640 | * @param Node $string The string to search and replace in. |
||
| 641 | * @param Node $pattern A string or regular expression pattern to search for. |
||
| 642 | * @param Node $replacement The string to replace the matched pattern with. |
||
| 643 | * @param Node $flags (Optional) regular expression flags. |
||
| 644 | * |
||
| 645 | * @return QuotedNode |
||
| 646 | * |
||
| 647 | * @see http://lesscss.org/functions/#string-functions-replace |
||
| 648 | */ |
||
| 649 | public function replace(Node $string, Node $pattern, Node $replacement, Node $flags = null) |
||
| 684 | |||
| 685 | /** |
||
| 686 | * Inlines a resource and falls back to url() if the ieCompat option is on |
||
| 687 | * and the resource is too large, or if you use the function in the browser. |
||
| 688 | * If the mime is not given then node uses the mime package to determine the correct mime type. |
||
| 689 | * |
||
| 690 | * @param Node $mimeType A mime type string |
||
| 691 | * @param Node $url The URL of the file to inline. |
||
| 692 | * |
||
| 693 | * @return UrlNode |
||
| 694 | * |
||
| 695 | * @throws IOException |
||
| 696 | */ |
||
| 697 | public function dataUri(Node $mimeType, Node $filePath = null) |
||
| 758 | |||
| 759 | /** |
||
| 760 | * Rounds up to an integer. |
||
| 761 | * |
||
| 762 | * @param Node $number |
||
| 763 | * |
||
| 764 | * @return DimensionNode |
||
| 765 | */ |
||
| 766 | public function ceil($number) |
||
| 770 | |||
| 771 | /** |
||
| 772 | * Rounds down to an integer. |
||
| 773 | * |
||
| 774 | * @param Node $number |
||
| 775 | * |
||
| 776 | * @return Node |
||
| 777 | */ |
||
| 778 | public function floor($number) |
||
| 782 | |||
| 783 | /** |
||
| 784 | * Converts to a %, e.g. 0.5 -> 50%. |
||
| 785 | * |
||
| 786 | * @param Node $number |
||
| 787 | * |
||
| 788 | * @return DimensionNode |
||
| 789 | */ |
||
| 790 | public function percentage(Node $number) |
||
| 796 | |||
| 797 | /** |
||
| 798 | * Rounds a number to a number of places. |
||
| 799 | * |
||
| 800 | * @param string|Node $number The number to round |
||
| 801 | * @param int $places The precision |
||
| 802 | * |
||
| 803 | * @return DimensionNode |
||
| 804 | */ |
||
| 805 | public function round($number, DimensionNode $places = null) |
||
| 818 | |||
| 819 | /** |
||
| 820 | * Calculates square root of a number. |
||
| 821 | * |
||
| 822 | * @param mixed $number |
||
| 823 | * |
||
| 824 | * @return mixed |
||
| 825 | */ |
||
| 826 | public function sqrt($number) |
||
| 830 | |||
| 831 | /** |
||
| 832 | * Absolute value of a number. |
||
| 833 | * |
||
| 834 | * @param mixed $number The number |
||
| 835 | * |
||
| 836 | * @return mixed |
||
| 837 | */ |
||
| 838 | public function abs($number) |
||
| 842 | |||
| 843 | /** |
||
| 844 | * Sine function. |
||
| 845 | * |
||
| 846 | * @param string $number The number |
||
| 847 | * |
||
| 848 | * @return mixed |
||
| 849 | */ |
||
| 850 | public function sin($number) |
||
| 854 | |||
| 855 | /** |
||
| 856 | * Arcsine - inverse of sine function. |
||
| 857 | * |
||
| 858 | * @param string $number |
||
| 859 | * |
||
| 860 | * @return mixed |
||
| 861 | */ |
||
| 862 | public function asin($number) |
||
| 866 | |||
| 867 | /** |
||
| 868 | * Cosine function. |
||
| 869 | * |
||
| 870 | * @param string $number |
||
| 871 | * |
||
| 872 | * @return mixed |
||
| 873 | */ |
||
| 874 | public function cos($number) |
||
| 878 | |||
| 879 | /** |
||
| 880 | * Arc cosine - inverse of cosine function. |
||
| 881 | * |
||
| 882 | * @param string $number |
||
| 883 | * |
||
| 884 | * @return mixed |
||
| 885 | */ |
||
| 886 | public function acos($number) |
||
| 890 | |||
| 891 | /** |
||
| 892 | * Tangent function. |
||
| 893 | * |
||
| 894 | * @param mixed $number |
||
| 895 | * |
||
| 896 | * @return mixed |
||
| 897 | */ |
||
| 898 | public function tan($number) |
||
| 902 | |||
| 903 | /** |
||
| 904 | * Arc tangent - inverse of tangent function. |
||
| 905 | * |
||
| 906 | * @param mixed $number |
||
| 907 | * |
||
| 908 | * @return mixed |
||
| 909 | */ |
||
| 910 | public function atan($number) |
||
| 914 | |||
| 915 | /** |
||
| 916 | * Does the math using Math. |
||
| 917 | * |
||
| 918 | * @param string $func The math function like sqrt, floor... |
||
| 919 | * @param DimensionNode|int $number The number |
||
| 920 | * @param UnitNode|string $unit The unit |
||
| 921 | * @param mixed ...$argument1 Argument for the mathematical function |
||
| 922 | * @param mixed ...$argument2 Argument for the mathematical function |
||
| 923 | * |
||
| 924 | * @return mixed |
||
| 925 | * |
||
| 926 | * @throws CompilerException |
||
| 927 | */ |
||
| 928 | protected function doMath($func, $number, $unit = null /*, $arguments...*/) |
||
| 960 | |||
| 961 | /** |
||
| 962 | * Returns pi. |
||
| 963 | * |
||
| 964 | * @return DimensionNode |
||
| 965 | */ |
||
| 966 | public function pi() |
||
| 970 | |||
| 971 | /** |
||
| 972 | * First argument raised to the power of the second argument. |
||
| 973 | * |
||
| 974 | * @param Node $number |
||
| 975 | * @param Node $exponent |
||
| 976 | * |
||
| 977 | * @throws CompilerException |
||
| 978 | * |
||
| 979 | * @return DimensionNode |
||
| 980 | */ |
||
| 981 | public function pow($number, $exponent) |
||
| 994 | |||
| 995 | /** |
||
| 996 | * First argument modulus second argument. |
||
| 997 | * |
||
| 998 | * @param DimensionNode $number1 |
||
| 999 | * @param DimensionNode $number2 |
||
| 1000 | * |
||
| 1001 | * @return DimensionNode |
||
| 1002 | */ |
||
| 1003 | public function mod(DimensionNode $number1, DimensionNode $number2) |
||
| 1007 | |||
| 1008 | /** |
||
| 1009 | * Converts between number types. |
||
| 1010 | * |
||
| 1011 | * @param DimensionNode $number |
||
| 1012 | * @param Node $units |
||
| 1013 | * |
||
| 1014 | * @return DimensionNode|null |
||
| 1015 | */ |
||
| 1016 | public function convert(Node $number, Node $units) |
||
| 1024 | |||
| 1025 | /** |
||
| 1026 | * Changes number units without converting it. |
||
| 1027 | * |
||
| 1028 | * @param Node $number The dimension |
||
| 1029 | * @param Node $unit The unit |
||
| 1030 | * |
||
| 1031 | * @throws CompilerException |
||
| 1032 | * |
||
| 1033 | * @return DimensionNode |
||
| 1034 | */ |
||
| 1035 | public function unit(Node $number, Node $unit = null) |
||
| 1058 | |||
| 1059 | /** |
||
| 1060 | * Returns units of a number. |
||
| 1061 | * |
||
| 1062 | * @param DimensionNode $node |
||
| 1063 | * |
||
| 1064 | * @return AnonymousNode |
||
| 1065 | * |
||
| 1066 | * @see http://lesscss.org/functions/#misc-functions-get-unit |
||
| 1067 | */ |
||
| 1068 | public function getunit(DimensionNode $node) |
||
| 1072 | |||
| 1073 | /** |
||
| 1074 | * Converts string or escaped value into color. |
||
| 1075 | * |
||
| 1076 | * @param Node $string |
||
| 1077 | * |
||
| 1078 | * @throws CompilerException |
||
| 1079 | * @returns ColorNode |
||
| 1080 | */ |
||
| 1081 | public function color(Node $string) |
||
| 1102 | |||
| 1103 | /** |
||
| 1104 | * Converts to a color. |
||
| 1105 | * |
||
| 1106 | * @param Node|int $red The red component of a color |
||
| 1107 | * @param Node|int $green The green component of a color |
||
| 1108 | * @param Node|int $blue The blue component of a color |
||
| 1109 | * |
||
| 1110 | * @return ColorNode |
||
| 1111 | */ |
||
| 1112 | public function rgb($red, $green, $blue) |
||
| 1116 | |||
| 1117 | /** |
||
| 1118 | * Converts to a color. |
||
| 1119 | * |
||
| 1120 | * @param Node $red The red component of a color |
||
| 1121 | * @param Node $green The green component of a color |
||
| 1122 | * @param Node $blue The blue component of a color |
||
| 1123 | * @param Node|float $alpha The alpha channel |
||
| 1124 | * |
||
| 1125 | * @return ColorNode |
||
| 1126 | */ |
||
| 1127 | public function rgba($red, $green, $blue, $alpha) |
||
| 1133 | |||
| 1134 | /** |
||
| 1135 | * Scales the number to percentage. |
||
| 1136 | * |
||
| 1137 | * @param DimensionNode $n The number |
||
| 1138 | * @param int $size |
||
| 1139 | * |
||
| 1140 | * @return float |
||
| 1141 | */ |
||
| 1142 | protected function scaled($n, $size = 255) |
||
| 1150 | |||
| 1151 | /** |
||
| 1152 | * Converts the $number to "real" number. |
||
| 1153 | * |
||
| 1154 | * @param DimensionNode|int|float $number |
||
| 1155 | * |
||
| 1156 | * @return float |
||
| 1157 | * |
||
| 1158 | * @throws InvalidArgumentException |
||
| 1159 | */ |
||
| 1160 | public function number($number) |
||
| 1172 | |||
| 1173 | /** |
||
| 1174 | * Creates a `#AARRGGBB`. |
||
| 1175 | * |
||
| 1176 | * @param Color $color The color |
||
| 1177 | * |
||
| 1178 | * @return AnonymousNode |
||
| 1179 | */ |
||
| 1180 | public function argb(Node $color) |
||
| 1188 | |||
| 1189 | /** |
||
| 1190 | * Creates a color. |
||
| 1191 | * |
||
| 1192 | * @param Node $hue The hue |
||
| 1193 | * @param Node $saturation The saturation |
||
| 1194 | * @param Node $lightness The lightness |
||
| 1195 | * |
||
| 1196 | * @return ColorNode |
||
| 1197 | */ |
||
| 1198 | public function hsl($hue, $saturation, $lightness) |
||
| 1202 | |||
| 1203 | /** |
||
| 1204 | * Creates a color from hsla color namespace. |
||
| 1205 | * |
||
| 1206 | * @param mixed $hue |
||
| 1207 | * @param mixed $saturation |
||
| 1208 | * @param mixed $lightness |
||
| 1209 | * @param mixed $alpha |
||
| 1210 | * |
||
| 1211 | * @return ColorNode |
||
| 1212 | */ |
||
| 1213 | public function hsla($hue, $saturation, $lightness, $alpha) |
||
| 1230 | |||
| 1231 | /** |
||
| 1232 | * Helper for hsla(). |
||
| 1233 | * |
||
| 1234 | * @param float $h |
||
| 1235 | * @param float $m1 |
||
| 1236 | * @param float $m2 |
||
| 1237 | * |
||
| 1238 | * @return float |
||
| 1239 | */ |
||
| 1240 | protected function hslaHue($h, $m1, $m2) |
||
| 1253 | |||
| 1254 | /** |
||
| 1255 | * Creates a color. |
||
| 1256 | * |
||
| 1257 | * @param int $hue The hue |
||
| 1258 | * @param int $saturation The saturation |
||
| 1259 | * @param int $value The value |
||
| 1260 | */ |
||
| 1261 | public function hsv($hue, $saturation, $value) |
||
| 1265 | |||
| 1266 | /** |
||
| 1267 | * Creates a color. |
||
| 1268 | * |
||
| 1269 | * @param int $hue The hue |
||
| 1270 | * @param int $saturation The saturation |
||
| 1271 | * @param int $value The value |
||
| 1272 | * @param int $alpha The alpha channel |
||
| 1273 | */ |
||
| 1274 | public function hsva($hue, $saturation, $value, $alpha) |
||
| 1307 | |||
| 1308 | /** |
||
| 1309 | * Returns the `hue` channel of the $color in the HSL space. |
||
| 1310 | * |
||
| 1311 | * @param ColorNode $color |
||
| 1312 | * |
||
| 1313 | * @return DimensionNode |
||
| 1314 | */ |
||
| 1315 | public function hue(ColorNode $color) |
||
| 1319 | |||
| 1320 | /** |
||
| 1321 | * Returns the `saturation` channel of the $color in the HSL space. |
||
| 1322 | * |
||
| 1323 | * @param ColorNode $color |
||
| 1324 | * |
||
| 1325 | * @return DimensionNode |
||
| 1326 | */ |
||
| 1327 | public function saturation(ColorNode $color) |
||
| 1331 | |||
| 1332 | /** |
||
| 1333 | * Returns the 'lightness' channel of @color in the HSL space. |
||
| 1334 | * |
||
| 1335 | * @param ColorNode $color |
||
| 1336 | * |
||
| 1337 | * @return DimensionNode |
||
| 1338 | */ |
||
| 1339 | public function lightness(ColorNode $color) |
||
| 1343 | |||
| 1344 | /** |
||
| 1345 | * Returns the `hue` channel of @color in the HSV space. |
||
| 1346 | * |
||
| 1347 | * @param ColorNode $color |
||
| 1348 | * |
||
| 1349 | * @return string |
||
| 1350 | */ |
||
| 1351 | public function hsvhue(Node $color) |
||
| 1360 | |||
| 1361 | /** |
||
| 1362 | * Returns the `saturation` channel of @color in the HSV space. |
||
| 1363 | * |
||
| 1364 | * @param ColorNode $color |
||
| 1365 | * |
||
| 1366 | * @return string |
||
| 1367 | */ |
||
| 1368 | public function hsvsaturation(Node $color) |
||
| 1377 | |||
| 1378 | /** |
||
| 1379 | * Returns the 'value' channel of @color in the HSV space. |
||
| 1380 | * |
||
| 1381 | * @param ColorNode $color |
||
| 1382 | * |
||
| 1383 | * @return string |
||
| 1384 | */ |
||
| 1385 | public function hsvvalue(Node $color) |
||
| 1394 | |||
| 1395 | /** |
||
| 1396 | * Returns the 'red' channel of @color. |
||
| 1397 | * |
||
| 1398 | * @param ColorNode $color |
||
| 1399 | * |
||
| 1400 | * @return string |
||
| 1401 | */ |
||
| 1402 | public function red(ColorNode $color) |
||
| 1406 | |||
| 1407 | /** |
||
| 1408 | * Returns the 'green' channel of @color. |
||
| 1409 | * |
||
| 1410 | * @param ColorNode $color |
||
| 1411 | * |
||
| 1412 | * @return string |
||
| 1413 | */ |
||
| 1414 | public function green(ColorNode $color) |
||
| 1418 | |||
| 1419 | /** |
||
| 1420 | * Returns the 'blue' channel of @color. |
||
| 1421 | * |
||
| 1422 | * @param ColorNode $color |
||
| 1423 | * |
||
| 1424 | * @return DimensionNode |
||
| 1425 | */ |
||
| 1426 | public function blue(ColorNode $color) |
||
| 1430 | |||
| 1431 | /** |
||
| 1432 | * Returns the 'alpha' channel of the $color. |
||
| 1433 | * |
||
| 1434 | * @param ColorNode $color The color |
||
| 1435 | * |
||
| 1436 | * @return DimensionNode |
||
| 1437 | */ |
||
| 1438 | public function alpha(Node $color) |
||
| 1446 | |||
| 1447 | /** |
||
| 1448 | * Returns the 'luma' value (perceptual brightness) of the $color. |
||
| 1449 | * |
||
| 1450 | * @param ColorNode $color |
||
| 1451 | * |
||
| 1452 | * @return DimensionNode |
||
| 1453 | */ |
||
| 1454 | public function luma(ColorNode $color) |
||
| 1458 | |||
| 1459 | /** |
||
| 1460 | * Returns the luminance of the color. |
||
| 1461 | * |
||
| 1462 | * @param ColorNode $color |
||
| 1463 | * |
||
| 1464 | * @return DimensionNode |
||
| 1465 | */ |
||
| 1466 | public function luminance(ColorNode $color) |
||
| 1470 | |||
| 1471 | /** |
||
| 1472 | * Return a color 10% points *more* saturated. |
||
| 1473 | * |
||
| 1474 | * @param ColorNode $color |
||
| 1475 | * @param Node $percentage The percentage |
||
| 1476 | * @param Node $method The color method |
||
| 1477 | * |
||
| 1478 | * @throws InvalidArgumentException |
||
| 1479 | * |
||
| 1480 | * @return ColorNode* |
||
| 1481 | */ |
||
| 1482 | public function saturate(Node $color, Node $percentage = null, Node $method = null) |
||
| 1504 | |||
| 1505 | /** |
||
| 1506 | * Return a color 10% points *less* saturated. |
||
| 1507 | * |
||
| 1508 | * @param ColorNode $color |
||
| 1509 | * @param Node $percentage The percentage |
||
| 1510 | * @param Node $method The color method |
||
| 1511 | * |
||
| 1512 | * @throws InvalidArgumentException |
||
| 1513 | * |
||
| 1514 | * @return ColorNode |
||
| 1515 | */ |
||
| 1516 | public function desaturate(ColorNode $color, Node $percentage = null, Node $method = null) |
||
| 1532 | |||
| 1533 | /** |
||
| 1534 | * Return a color 10% points *lighter*. |
||
| 1535 | * |
||
| 1536 | * @param Node $color |
||
| 1537 | * @param Node $percentage The percentage (Default to 10%) |
||
| 1538 | * @param Node $method The color method |
||
| 1539 | * |
||
| 1540 | * @throws InvalidArgumentException |
||
| 1541 | * |
||
| 1542 | * @return ColorNode |
||
| 1543 | */ |
||
| 1544 | public function lighten(Node $color, Node $percentage = null, Node $method = null) |
||
| 1559 | |||
| 1560 | /** |
||
| 1561 | * Return a color 10% points *darker*. |
||
| 1562 | * |
||
| 1563 | * @param Node $color |
||
| 1564 | * @param DimensionNode $percentage The percentage (Default to 10%) |
||
| 1565 | * @param Node $method The method |
||
| 1566 | * |
||
| 1567 | * @return ColorNode |
||
| 1568 | * |
||
| 1569 | * @throws InvalidArgumentException |
||
| 1570 | */ |
||
| 1571 | public function darken(Node $color, DimensionNode $percentage = null, Node $method = null) |
||
| 1586 | |||
| 1587 | /** |
||
| 1588 | * Return a color 10% points *less* transparent. |
||
| 1589 | * |
||
| 1590 | * @param ColorNode $color |
||
| 1591 | * @param DimensionNode $percentage The percentage (Default to 10%) |
||
| 1592 | * @param Node $method The method |
||
| 1593 | * |
||
| 1594 | * @return ColorNode |
||
| 1595 | * |
||
| 1596 | * @throws InvalidArgumentException |
||
| 1597 | */ |
||
| 1598 | public function fadein(ColorNode $color, DimensionNode $percentage = null, Node $method = null) |
||
| 1613 | |||
| 1614 | /** |
||
| 1615 | * Return a color 10% points *more* transparent. |
||
| 1616 | * |
||
| 1617 | * @param ColorNode $color |
||
| 1618 | * @param DimensionNode $percentage The percentage (Default to 10%) |
||
| 1619 | * @param Node $method The method |
||
| 1620 | * |
||
| 1621 | * @return ColorNode |
||
| 1622 | * |
||
| 1623 | * @throws InvalidArgumentException |
||
| 1624 | */ |
||
| 1625 | public function fadeout(ColorNode $color, DimensionNode $percentage = null, Node $method = null) |
||
| 1640 | |||
| 1641 | /** |
||
| 1642 | * Return $color with 50% transparency. |
||
| 1643 | * |
||
| 1644 | * @param ColorNode $color |
||
| 1645 | * @param DimensionNode $percentage |
||
| 1646 | * |
||
| 1647 | * @return string |
||
| 1648 | */ |
||
| 1649 | public function fade(ColorNode $color, DimensionNode $percentage = null) |
||
| 1663 | |||
| 1664 | /** |
||
| 1665 | * Return a color with a 10 degree larger in hue. |
||
| 1666 | * |
||
| 1667 | * @param ColorNode $color |
||
| 1668 | * @param DimensionNode $degrees |
||
| 1669 | * |
||
| 1670 | * @return ColorNode |
||
| 1671 | */ |
||
| 1672 | public function spin(ColorNode $color, DimensionNode $degrees = null) |
||
| 1680 | |||
| 1681 | /** |
||
| 1682 | * Return a mix of $color1 and $color2 with given $weightPercentage (defaults to 50%). |
||
| 1683 | * |
||
| 1684 | * @param Node $color1 |
||
| 1685 | * @param Node $color2 |
||
| 1686 | * @param DimensionNode $weightPercentage |
||
| 1687 | * |
||
| 1688 | * @return ColorNode |
||
| 1689 | * |
||
| 1690 | * @link http://sass-lang.com |
||
| 1691 | * |
||
| 1692 | * @copyright 2006-2009 Hampton Catlin, Nathan Weizenbaum, and Chris Eppstein |
||
| 1693 | */ |
||
| 1694 | public function mix(Node $color1, Node $color2, DimensionNode $weightPercentage = null) |
||
| 1726 | |||
| 1727 | /** |
||
| 1728 | * Return a color mixed 10% with white. |
||
| 1729 | * |
||
| 1730 | * @param Node $color |
||
| 1731 | * |
||
| 1732 | * @return string |
||
| 1733 | */ |
||
| 1734 | public function tint(Node $color, Node $percentage = null) |
||
| 1738 | |||
| 1739 | /** |
||
| 1740 | * Return a color mixed 10% with black. |
||
| 1741 | * |
||
| 1742 | * @param Node $color |
||
| 1743 | * @param Node $percentage |
||
| 1744 | * |
||
| 1745 | * @return string |
||
| 1746 | */ |
||
| 1747 | public function shade(Node $color, Node $percentage = null) |
||
| 1751 | |||
| 1752 | /** |
||
| 1753 | * Returns a grey, 100% desaturated color. |
||
| 1754 | * |
||
| 1755 | * @param ColorNode $color |
||
| 1756 | * |
||
| 1757 | * @return string |
||
| 1758 | */ |
||
| 1759 | public function greyscale(ColorNode $color) |
||
| 1763 | |||
| 1764 | /** |
||
| 1765 | * Return @darkColor if @color is > 43% luma otherwise return @lightColor, see notes. |
||
| 1766 | * |
||
| 1767 | * @param Node $color |
||
| 1768 | * @param ColorNode|null $darkColor |
||
| 1769 | * @param ColorNode|null $lightColor |
||
| 1770 | * @param DimensionNode|null $thresholdPercentage |
||
| 1771 | * |
||
| 1772 | * @return ColorNode |
||
| 1773 | */ |
||
| 1774 | public function contrast( |
||
| 1819 | |||
| 1820 | /** |
||
| 1821 | * Multiplies the $color1 with $color2. |
||
| 1822 | * |
||
| 1823 | * @param ColorNode $color1 The first color |
||
| 1824 | * @param ColorNode $color2 The second color |
||
| 1825 | * |
||
| 1826 | * @return ColorNode |
||
| 1827 | */ |
||
| 1828 | public function multiply(ColorNode $color1, ColorNode $color2) |
||
| 1832 | |||
| 1833 | /** |
||
| 1834 | * Screen. |
||
| 1835 | * |
||
| 1836 | * @param ColorNode $color1 The first color |
||
| 1837 | * @param ColorNode $color2 The second color |
||
| 1838 | * |
||
| 1839 | * @return ColorNode |
||
| 1840 | */ |
||
| 1841 | public function screen(ColorNode $color1, ColorNode $color2) |
||
| 1845 | |||
| 1846 | /** |
||
| 1847 | * Combines the effects of both multiply and screen. Conditionally make light channels lighter |
||
| 1848 | * and dark channels darker. Note: The results of the conditions are determined by the |
||
| 1849 | * first color parameter. |
||
| 1850 | * |
||
| 1851 | * @param ColorNode $color1 A base color object. Also the determinant color to make the result lighter or darker. |
||
| 1852 | * @param ColorNode $color2 A color object to overlay. |
||
| 1853 | * |
||
| 1854 | * @return ColorNode |
||
| 1855 | * |
||
| 1856 | * @see http://lesscss.org/functions/#color-blending-overlay |
||
| 1857 | */ |
||
| 1858 | public function overlay(ColorNode $color1, ColorNode $color2) |
||
| 1862 | |||
| 1863 | /** |
||
| 1864 | * Softlight - Similar to overlay but avoids pure black resulting in pure black, |
||
| 1865 | * and pure white resulting in pure white. |
||
| 1866 | * |
||
| 1867 | * @param ColorNode $color1 The first color |
||
| 1868 | * @param ColorNode $color2 The second color |
||
| 1869 | * |
||
| 1870 | * @return ColorNode |
||
| 1871 | * |
||
| 1872 | * @see http://lesscss.org/functions/#color-blending-softlight |
||
| 1873 | */ |
||
| 1874 | public function softlight(ColorNode $color1, ColorNode $color2) |
||
| 1878 | |||
| 1879 | /** |
||
| 1880 | * Hardlight filter. |
||
| 1881 | * |
||
| 1882 | * @param ColorNode $color1 The first color |
||
| 1883 | * @param ColorNode $color2 The second color |
||
| 1884 | * |
||
| 1885 | * @return ColorNode |
||
| 1886 | */ |
||
| 1887 | public function hardlight(ColorNode $color1, ColorNode $color2) |
||
| 1891 | |||
| 1892 | /** |
||
| 1893 | * Difference. |
||
| 1894 | * |
||
| 1895 | * @param ColorNode $color1 The first color |
||
| 1896 | * @param ColorNode $color2 The second color |
||
| 1897 | * |
||
| 1898 | * @return ColorNode |
||
| 1899 | */ |
||
| 1900 | public function difference(ColorNode $color1, ColorNode $color2) |
||
| 1904 | |||
| 1905 | /** |
||
| 1906 | * Exclusion. |
||
| 1907 | * |
||
| 1908 | * @param ColorNode $color1 The first color |
||
| 1909 | * @param ColorNode $color2 The second color |
||
| 1910 | * |
||
| 1911 | * @return ColorNode |
||
| 1912 | */ |
||
| 1913 | public function exclusion(ColorNode $color1, ColorNode $color2) |
||
| 1917 | |||
| 1918 | /** |
||
| 1919 | * Average. |
||
| 1920 | * |
||
| 1921 | * @param ColorNode $color1 The first color |
||
| 1922 | * @param ColorNode $color2 The second color |
||
| 1923 | * |
||
| 1924 | * @return ColorNode |
||
| 1925 | */ |
||
| 1926 | public function average(ColorNode $color1, ColorNode $color2) |
||
| 1930 | |||
| 1931 | /** |
||
| 1932 | * Negation. |
||
| 1933 | * |
||
| 1934 | * @param ColorNode $color1 The first color |
||
| 1935 | * @param ColorNode $color2 The second color |
||
| 1936 | * |
||
| 1937 | * @return ColorNode |
||
| 1938 | */ |
||
| 1939 | public function negation(ColorNode $color1, ColorNode $color2) |
||
| 1943 | |||
| 1944 | /** |
||
| 1945 | * Returns true if passed a color, including keyword colors. |
||
| 1946 | * |
||
| 1947 | * @param Node $colorOrAnything |
||
| 1948 | * |
||
| 1949 | * @return KeywordNode |
||
| 1950 | */ |
||
| 1951 | public function iscolor(Node $colorOrAnything) |
||
| 1955 | |||
| 1956 | /** |
||
| 1957 | * Returns true if a number of any unit. |
||
| 1958 | * |
||
| 1959 | * @param Node $numberOrAnything |
||
| 1960 | * |
||
| 1961 | * @return KeywordNode |
||
| 1962 | */ |
||
| 1963 | public function isnumber(Node $numberOrAnything) |
||
| 1967 | |||
| 1968 | /** |
||
| 1969 | * Returns true if it is passed a string. |
||
| 1970 | * |
||
| 1971 | * @param Node $stringOrAnything |
||
| 1972 | * |
||
| 1973 | * @return KeywordNode |
||
| 1974 | */ |
||
| 1975 | public function isstring(Node $stringOrAnything) |
||
| 1979 | |||
| 1980 | /** |
||
| 1981 | * Returns true if it is passed keyword. |
||
| 1982 | * |
||
| 1983 | * @param Node $numberOrAnything |
||
| 1984 | * |
||
| 1985 | * @return KeywordNode |
||
| 1986 | */ |
||
| 1987 | public function iskeyword(Node $keywordOrAnything) |
||
| 1991 | |||
| 1992 | /** |
||
| 1993 | * Returns true if it is a string and a url. |
||
| 1994 | * |
||
| 1995 | * @param mixed $urlOrAnything |
||
| 1996 | * |
||
| 1997 | * @return bool |
||
| 1998 | */ |
||
| 1999 | public function isurl(Node $urlOrAnything) |
||
| 2003 | |||
| 2004 | /** |
||
| 2005 | * Returns true if it is a number and a px. |
||
| 2006 | * |
||
| 2007 | * @param Node $urlOrAnything The node to check |
||
| 2008 | * |
||
| 2009 | * @return KeywordNode |
||
| 2010 | */ |
||
| 2011 | public function ispixel(Node $pixelOrAnything) |
||
| 2019 | |||
| 2020 | /** |
||
| 2021 | * Returns true if it is a number and a %. |
||
| 2022 | * |
||
| 2023 | * @param Node $percentageOrAnything |
||
| 2024 | * |
||
| 2025 | * @return KeywordNode |
||
| 2026 | */ |
||
| 2027 | public function ispercentage(Node $percentageOrAnything) |
||
| 2035 | |||
| 2036 | /** |
||
| 2037 | * Returns true if it is a number and an em. |
||
| 2038 | * |
||
| 2039 | * @param Node $emOrAnything |
||
| 2040 | * |
||
| 2041 | * @return KeywordNode |
||
| 2042 | */ |
||
| 2043 | public function isem(Node $emOrAnything) |
||
| 2051 | |||
| 2052 | /** |
||
| 2053 | * returns if a parameter is a number and is in a particular unit. |
||
| 2054 | * |
||
| 2055 | * @param Node $node |
||
| 2056 | * @param Node $unit The unit to check |
||
| 2057 | * |
||
| 2058 | * @return bool |
||
| 2059 | */ |
||
| 2060 | public function isunit(Node $node, Node $unit = null) |
||
| 2070 | |||
| 2071 | /** |
||
| 2072 | * Returns true if the node is detached ruleset. |
||
| 2073 | * |
||
| 2074 | * @param Node $node |
||
| 2075 | * |
||
| 2076 | * @return bool |
||
| 2077 | */ |
||
| 2078 | public function isruleset(Node $node) |
||
| 2082 | |||
| 2083 | /** |
||
| 2084 | * Creates a SVG gradient. |
||
| 2085 | * |
||
| 2086 | * @param Node $direction |
||
| 2087 | * @param Node ...$stop1 |
||
| 2088 | * |
||
| 2089 | * @return UrlNode |
||
| 2090 | * |
||
| 2091 | * @throws CompilerException If the arguments are invalid |
||
| 2092 | */ |
||
| 2093 | public function svggradient(Node $direction /* $stop1, $stop2, ... */) |
||
| 2191 | |||
| 2192 | /** |
||
| 2193 | * Default function. |
||
| 2194 | * |
||
| 2195 | * @return KeywordNode|null |
||
| 2196 | * |
||
| 2197 | * @throws Exception |
||
| 2198 | */ |
||
| 2199 | public function defaultFunc() |
||
| 2203 | |||
| 2204 | /** |
||
| 2205 | * Returns the image size. |
||
| 2206 | * |
||
| 2207 | * @param Node $node The path node |
||
| 2208 | * |
||
| 2209 | * @return ExpressionNode |
||
| 2210 | * |
||
| 2211 | * @throws IOException |
||
| 2212 | */ |
||
| 2213 | public function imageSize(Node $node) |
||
| 2224 | |||
| 2225 | /** |
||
| 2226 | * Returns the image width. |
||
| 2227 | * |
||
| 2228 | * @param Node $node The path node |
||
| 2229 | * |
||
| 2230 | * @return DimensionNode |
||
| 2231 | * |
||
| 2232 | * @throws IOException |
||
| 2233 | */ |
||
| 2234 | public function imageWidth(Node $node) |
||
| 2240 | |||
| 2241 | /** |
||
| 2242 | * Returns the image height. |
||
| 2243 | * |
||
| 2244 | * @param Node $node The path node |
||
| 2245 | * |
||
| 2246 | * @return DimensionNode |
||
| 2247 | * |
||
| 2248 | * @throws IOException |
||
| 2249 | */ |
||
| 2250 | public function imageHeight(Node $node) |
||
| 2256 | |||
| 2257 | /** |
||
| 2258 | * Returns the width and height of the image. |
||
| 2259 | * |
||
| 2260 | * @param Node $path |
||
| 2261 | * |
||
| 2262 | * @throws IOException |
||
| 2263 | * |
||
| 2264 | * @return array |
||
| 2265 | */ |
||
| 2266 | protected function getImageSize(Node $path) |
||
| 2296 | |||
| 2297 | /** |
||
| 2298 | * Returns the file path, takes care about relative urls. |
||
| 2299 | * |
||
| 2300 | * @param string $path |
||
| 2301 | * |
||
| 2302 | * @return mixed|string |
||
| 2303 | */ |
||
| 2304 | protected function getFilePath($path) |
||
| 2319 | |||
| 2320 | protected function doMinmax($isMin, $args) |
||
| 2397 | |||
| 2398 | /** |
||
| 2399 | * Checks if the given object is of this class or has this class as one of its parents. |
||
| 2400 | * |
||
| 2401 | * @param Node $node |
||
| 2402 | * @param string $className The className to check |
||
| 2403 | * |
||
| 2404 | * @return KeywordNode |
||
| 2405 | */ |
||
| 2406 | protected function isA(Node $node, $className) |
||
| 2414 | |||
| 2415 | /** |
||
| 2416 | * Clamps the value. |
||
| 2417 | * |
||
| 2418 | * @param int $value |
||
| 2419 | * |
||
| 2420 | * @return int |
||
| 2421 | */ |
||
| 2422 | protected function clamp($value) |
||
| 2426 | |||
| 2427 | /** |
||
| 2428 | * Convert the given node to color node. |
||
| 2429 | * |
||
| 2430 | * @param Node $node The node |
||
| 2431 | * @param null $exceptionMessage ILess\Exception\Exception message if the node could not be converted to color node |
||
| 2432 | * |
||
| 2433 | * @return ColorNode |
||
| 2434 | * |
||
| 2435 | * @throws InvalidArgumentException If the node could not be converted to color |
||
| 2436 | */ |
||
| 2437 | protected function getColorNode(Node $node, $exceptionMessage = null) |
||
| 2456 | |||
| 2457 | /** |
||
| 2458 | * Color blending. |
||
| 2459 | * |
||
| 2460 | * @param callable $mode |
||
| 2461 | * @param Color $color1 |
||
| 2462 | * @param Color $color2 |
||
| 2463 | * |
||
| 2464 | * @return ColorNode |
||
| 2465 | */ |
||
| 2466 | protected function colorBlend(callable $mode, Color $color1, Color $color2) |
||
| 2487 | |||
| 2488 | private function colorBlendMultiply($cb, $cs) |
||
| 2492 | |||
| 2493 | private function colorBlendScreen($cb, $cs) |
||
| 2497 | |||
| 2498 | private function colorBlendOverlay($cb, $cs) |
||
| 2506 | |||
| 2507 | private function colorBlendSoftlight($cb, $cs) |
||
| 2519 | |||
| 2520 | private function colorBlendHardlight($cb, $cs) |
||
| 2524 | |||
| 2525 | private function colorBlendDifference($cb, $cs) |
||
| 2529 | |||
| 2530 | private function colorBlendExclusion($cb, $cs) |
||
| 2534 | |||
| 2535 | private function colorBlendAverage($cb, $cs) |
||
| 2539 | |||
| 2540 | private function colorBlendNegation($cb, $cs) |
||
| 2544 | } |
||
| 2545 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.