HelperExpressionsProvider::getFunctions()   B
last analyzed

Complexity

Conditions 5
Paths 1

Size

Total Lines 51

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 51
c 0
b 0
f 0
rs 8.7579
cc 5
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * This is a part of Maketok site package.
4
 *
5
 * @author Oleg Kulik <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Maketok\DataMigration\Expression;
12
13
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
14
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
15
16
/**
17
 * @codeCoverageIgnore
18
 */
19
class HelperExpressionsProvider implements ExpressionFunctionProviderInterface
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function getFunctions()
25
    {
26
        return array(
27
            new ExpressionFunction('trim', function ($str, $mask = " \t\n\r\0\x0B") {
28
                return sprintf('trim(%1$s, %2$s)', $str, $mask);
29
            }, function ($arguments, $str, $mask = " \t\n\r\0\x0B") {
30
                if (!is_string($str)) {
31
                    return $str;
32
                }
33
34
                return trim($str, $mask);
35
            }),
36
            new ExpressionFunction('explode', function ($str, $expression) {
37
                return sprintf('explode(%1$s, %2$s)', $str, $expression);
38
            }, function ($arguments, $str, $expression) {
39
                if (!is_string($expression)) {
40
                    return $expression;
41
                }
42
43
                return explode($str, $expression);
44
            }),
45
            new ExpressionFunction('empty', function ($expression) {
46
                return sprintf('empty(%1$s)', $expression);
47
            }, function ($arguments, $expression) {
48
                return empty($expression);
49
            }),
50
            new ExpressionFunction('isset', function ($expression) {
51
                return sprintf('isset(%1$s)', $expression);
52
            }, function ($arguments, $expression) {
53
                return isset($expression);
54
            }),
55
            new ExpressionFunction('count', function ($array) {
56
                return sprintf('count(%1$s)', $array);
57
            }, function ($arguments, $array) {
58
                if (!is_array($array)) {
59
                    return $array;
60
                }
61
62
                return count($array);
63
            }),
64
            new ExpressionFunction('array_search', function ($needle, $haystack) {
65
                return sprintf('array_search(%1$s, %2$s)', $needle, $haystack);
66
            }, function ($arguments, $needle, $haystack) {
67
                if (!is_array($haystack)) {
68
                    return false;
69
                }
70
71
                return array_search($needle, $haystack);
72
            }),
73
        );
74
    }
75
}
76