RedirectRouteHandler   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 31
c 0
b 0
f 0
wmc 5
lcom 0
cbo 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 7 3
A isValid() 0 8 2
1
<?php
2
3
4
namespace ElementsFramework\DynamicRouting\Handler;
5
6
7
use ElementsFramework\DynamicRouting\Model\DynamicRoute;
8
use Illuminate\Http\Request;
9
use Illuminate\Http\Response;
10
use Illuminate\Support\Facades\Redirect;
11
12
class RedirectRouteHandler implements AbstractRouteTypeHandler
13
{
14
15
    /**
16
     * Uses the user input and the route definition to build and return a response for the user.
17
     * @param Request $request
18
     * @param DynamicRoute $route
19
     * @return Response
20
     */
21
    public function process(Request $request, DynamicRoute $route)
22
    {
23
        if(isset($route->configuration['status_code']) && in_array((int)$route->configuration['status_code'], [300,301,302,303,304,305,307,308])) {
0 ignored issues
show
Documentation introduced by
The property configuration does not exist on object<ElementsFramework...ing\Model\DynamicRoute>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
24
            return Redirect::to($route->configuration['target'], (int)$route->configuration['status_code']);
0 ignored issues
show
Documentation introduced by
The property configuration does not exist on object<ElementsFramework...ing\Model\DynamicRoute>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
25
        }
26
        return Redirect::to($route->configuration['target']);
0 ignored issues
show
Documentation introduced by
The property configuration does not exist on object<ElementsFramework...ing\Model\DynamicRoute>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
27
    }
28
29
    /**
30
     * Checks if the given route object is a valid route that can be handled with this handler.
31
     * @param DynamicRoute $route
32
     * @return boolean
33
     */
34
    public static function isValid(DynamicRoute $route)
35
    {
36
        if(isset($route->configuration['target']) === false) {
0 ignored issues
show
Documentation introduced by
The property configuration does not exist on object<ElementsFramework...ing\Model\DynamicRoute>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
37
            return false;
38
        }
39
40
        return true;
41
    }
42
}