Completed
Push — rest_role_limitation_href ( d5686e...3c57f9 )
by
unknown
25:30
created

PublishedRole::visit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 12
Ratio 100 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 12
loc 12
rs 9.4285
cc 1
eloc 8
nc 1
nop 3
1
<?php
2
3
/**
4
 * File containing the PublishedRole ValueObjectVisitor class.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 *
9
 * @version //autogentag//
10
 */
11
namespace eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor;
12
13
use eZ\Publish\Core\REST\Common\Output\Generator;
14
use eZ\Publish\Core\REST\Common\Output\Visitor;
15
16
/**
17
 * PublishedRole value object visitor.
18
 *
19
 * @todo coverage add unit test
20
 */
21 View Code Duplication
class PublishedRole extends Role
0 ignored issues
show
Duplication introduced by
This class 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...
22
{
23
    /**
24
     * Visit struct returned by controllers.
25
     *
26
     * @param \eZ\Publish\Core\REST\Common\Output\Visitor $visitor
27
     * @param \eZ\Publish\Core\REST\Common\Output\Generator $generator
28
     * @param \eZ\Publish\Core\REST\Server\Values\PublishedRole $data
29
     */
30
    public function visit(Visitor $visitor, Generator $generator, $data)
31
    {
32
        parent::visit($visitor, $generator, $data->role);
0 ignored issues
show
Documentation introduced by
$data->role is of type object<eZ\Publish\Core\R...Server\Values\RestRole>, but the function expects a object<eZ\Publish\Core\R...\Values\User\RoleDraft>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
33
        $visitor->setHeader(
34
            'Location',
35
            $this->router->generate(
36
                'ezpublish_rest_loadRole',
37
                array('roleId' => $data->role->id)
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<eZ\Publish\Core\R...Server\Values\RestRole>. 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...
38
            )
39
        );
40
        $visitor->setStatus(204);
41
    }
42
}
43