Completed
Push — 4.0 ( 268f2c...88f012 )
by Hideki
05:48 queued 10s
created

Twig/Extension/IgnoreRoutingNotFoundExtension.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.ec-cube.co.jp/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Eccube\Twig\Extension;
15
16
use Symfony\Bridge\Twig\Extension\RoutingExtension;
17
use Symfony\Component\Routing\Exception\RouteNotFoundException;
18
19
class IgnoreRoutingNotFoundExtension extends RoutingExtension
20
{
21
    /**
22
     * bind から URL へ変換します。
23
     * \Symfony\Bridge\Twig\Extension\RoutingExtension::getPath の処理を拡張し、
24
     * RouteNotFoundException 発生時に 文字列 "/404?bind={bind}" を返します。
25
     *
26
     * @param string $name
27
     * @param array $parameters
28
     * @param bool $relative
29
     *
30
     * @return string
31
     */
32 View Code Duplication
    public function getPath($name, $parameters = [], $relative = false)
33
    {
34
        try {
35
            return parent::getPath($name, $parameters, $relative);
36
        } catch (RouteNotFoundException $e) {
37
            log_warning($e->getMessage(), ['exception' => $e]);
38
39
            return parent::getPath('homepage').'404?bind='.$name;
40
        }
41
    }
42
43
    /**
44
     * bind から URL へ変換します。
45
     * \Symfony\Bridge\Twig\Extension\RoutingExtension::getUrl の処理を拡張し、
46
     * RouteNotFoundException 発生時に 文字列 "/404?bind={bind}" を返します。
47
     *
48
     * @param string $name
49
     * @param array $parameters
50
     * @param bool $schemeRelative
51
     *
52
     * @return string
53
     */
54 View Code Duplication
    public function getUrl($name, $parameters = [], $schemeRelative = false)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
55
    {
56
        try {
57
            return parent::getUrl($name, $parameters, $schemeRelative);
58
        } catch (RouteNotFoundException $e) {
59
            log_warning($e->getMessage(), ['exception' => $e]);
60
61
            return parent::getUrl('homepage').'404?bind='.$name;
62
        }
63
    }
64
}
65