Completed
Branch cleanup (6c017e)
by Paul
13:14
created

Identification::doWayfRedirect()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 0
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace LibLynx\Connect;
4
5
/**
6
 * Provides a simple wrapper around a LibLynx identification resource
7
 * @package LibLynx\Connect
8
 */
9
class Identification extends LibLynxResource
10
{
11
    public function isIdentified()
12
    {
13
        return $this->status == 'identified';
0 ignored issues
show
Documentation introduced by
The property status does not exist on object<LibLynx\Connect\Identification>. 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...
14
    }
15
16
    public function requiresWayf()
17
    {
18
        return $this->status == 'wayf';
0 ignored issues
show
Documentation introduced by
The property status does not exist on object<LibLynx\Connect\Identification>. 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...
19
    }
20
21
    public function getWayfUrl()
22
    {
23
        return $this->getLink('wayf');
24
    }
25
26
    public function doWayfRedirect()
27
    {
28
        $url = $this->getWayfUrl();
29
        if (!is_null($url)) {
30
            header("Location: $url");
31
            exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The method doWayfRedirect() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
32
        }
33
    }
34
}
35