Completed
Push — siteaccessaware-layer-only ( 7e91dd...edaec2 )
by André
56:17 queued 37:14
created

Views::createView()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 25
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 15
nc 2
nop 1
dl 0
loc 25
rs 8.8571
c 0
b 0
f 0
1
<?php
2
/**
3
 * @license For full copyright and license information view LICENSE file distributed with this source code.
4
 */
5
namespace eZ\Publish\Core\REST\Server\Controller;
6
7
use eZ\Publish\API\Repository\Exceptions\NotImplementedException;
8
use eZ\Publish\API\Repository\SearchService;
9
use eZ\Publish\API\Repository\Values\Content\Language;
10
use eZ\Publish\API\Repository\Values\Content\LocationQuery;
11
use eZ\Publish\Core\REST\Server\Controller;
12
use Symfony\Component\HttpFoundation\Request;
13
use eZ\Publish\Core\REST\Common\Message;
14
use eZ\Publish\Core\REST\Server\Values;
15
16
/**
17
 * Controller for Repository Views (Search, mostly).
18
 */
19
class Views extends Controller
20
{
21
    /**
22
     * @var \eZ\Publish\API\Repository\SearchService
23
     */
24
    private $searchService;
25
26
    public function __construct(SearchService $searchService)
27
    {
28
        $this->searchService = $searchService;
29
    }
30
31
    /**
32
     * Creates and executes a content view.
33
     *
34
     * @return \eZ\Publish\Core\REST\Server\Values\RestExecutedView
35
     */
36
    public function createView(Request $request)
37
    {
38
        $viewInput = $this->inputDispatcher->parse(
39
            new Message(
40
                array('Content-Type' => $request->headers->get('Content-Type')),
41
                $request->getContent()
0 ignored issues
show
Bug introduced by
It seems like $request->getContent() targeting Symfony\Component\HttpFo...n\Request::getContent() can also be of type resource; however, eZ\Publish\Core\REST\Common\Message::__construct() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
42
            )
43
        );
44
45
        if ($viewInput->query instanceof LocationQuery) {
0 ignored issues
show
Documentation introduced by
The property query does not exist on object<eZ\Publish\API\Re...ory\Values\ValueObject>. 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...
46
            $method = 'findLocations';
47
        } else {
48
            $method = 'findContent';
49
        }
50
51
        return new Values\RestExecutedView(
52
            array(
53
                'identifier' => $viewInput->identifier,
0 ignored issues
show
Documentation introduced by
The property identifier does not exist on object<eZ\Publish\API\Re...ory\Values\ValueObject>. 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...
54
                'searchResults' => $this->searchService->$method(
55
                    $viewInput->query,
0 ignored issues
show
Documentation introduced by
The property query does not exist on object<eZ\Publish\API\Re...ory\Values\ValueObject>. 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...
56
                    ['languages' => Language::ALL]
57
                ),
58
            )
59
        );
60
    }
61
62
    /**
63
     * List content views.
64
     *
65
     * @return NotImplementedException;
0 ignored issues
show
Documentation introduced by
The doc-type NotImplementedException; could not be parsed: Expected "|" or "end of type", but got ";" at position 23. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
66
     */
67
    public function listView()
68
    {
69
        return new NotImplementedException('ezpublish_rest.controller.content:listView');
70
    }
71
72
    /**
73
     * Get a content view.
74
     *
75
     * @return NotImplementedException;
0 ignored issues
show
Documentation introduced by
The doc-type NotImplementedException; could not be parsed: Expected "|" or "end of type", but got ";" at position 23. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
76
     */
77
    public function getView()
78
    {
79
        return new NotImplementedException('ezpublish_rest.controller.content:getView');
80
    }
81
82
    /**
83
     * Get a content view results.
84
     *
85
     * @return NotImplementedException;
0 ignored issues
show
Documentation introduced by
The doc-type NotImplementedException; could not be parsed: Expected "|" or "end of type", but got ";" at position 23. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
86
     */
87
    public function loadViewResults()
88
    {
89
        return new NotImplementedException('ezpublish_rest.controller.content:loadViewResults');
90
    }
91
}
92