Completed
Push — pull-request/7609 ( 4ccf63...393b85 )
by Kamil
146:59 queued 125:08
created

NotNullExpressionFunctionProvider   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 20
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getFunctions() 0 14 2
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Bundle\ResourceBundle\ExpressionLanguage;
13
14
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
15
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
16
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
17
18
/**
19
 * @author Mateusz Zalewski <[email protected]>
20
 */
21
final class NotNullExpressionFunctionProvider implements ExpressionFunctionProviderInterface
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function getFunctions()
27
    {
28
        return [
29
            new ExpressionFunction('notFoundOnNull', function ($result) {
30
                return sprintf('(null !== %1$s) ? %1$s : throw new NotFoundHttpException(\'Requested page is invalid.\')', $result);
31
            }, function ($arguments, $result) {
32
                if (null === $result) {
33
                    throw new NotFoundHttpException('Requested page is invalid.');
34
                }
35
36
                return $result;
37
            }),
38
        ];
39
    }
40
}
41