StringExpressionLanguageProvider   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A getFunctions() 0 16 2
1
<?php
2
3
namespace PhpEarth\Stats\ExpressionLanguage;
4
5
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
6
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
7
8
class StringExpressionLanguageProvider implements ExpressionFunctionProviderInterface
9
{
10
    public function getFunctions()
11
    {
12
        return [
13
            new ExpressionFunction('strlen', function ($str) {
14
                return sprintf('(is_string(%1$s) ? strlen(%1$s) : %1$s)', $str);
15
            }, function ($arguments, $str) {
16
                if (!is_string($str)) {
17
                    return $str;
18
                }
19
20
                return strlen($str);
21
            }),
22
            new ExpressionFunction('contains', function ($haystack, $needle) {
23
                return sprintf('(strpos(%1$s, %2$s) !== false) ? true : false', $haystack, $needle);
24
            }, function ($arguments, $haystack, $needle) {
25
                return strpos($haystack, $needle) !== false;
26
            }),
27
        ];
28
    }
29
}
30