Completed
Push — master ( 553bc5...721b68 )
by
unknown
49:35 queued 26:20
created

UserSession::visit()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 8
nc 2
nop 3
dl 13
loc 13
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * File containing the UserSession 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
namespace eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor;
10
11
use eZ\Publish\Core\REST\Common\Output\ValueObjectVisitor;
12
use eZ\Publish\Core\REST\Common\Output\Generator;
13
use eZ\Publish\Core\REST\Common\Output\Visitor;
14
use eZ\Publish\Core\REST\Server\Values\UserSession as UserSessionValue;
15
16
/**
17
 * UserSession value object visitor.
18
 */
19
class UserSession extends ValueObjectVisitor
20
{
21
    /**
22
     * Visit struct returned by controllers.
23
     *
24
     * @param \eZ\Publish\Core\REST\Common\Output\Visitor $visitor
25
     * @param \eZ\Publish\Core\REST\Common\Output\Generator $generator
26
     * @param \eZ\Publish\Core\REST\Server\Values\UserSession $data
27
     */
28 View Code Duplication
    public function visit(Visitor $visitor, Generator $generator, $data)
29
    {
30
        $status = $data->created ? 201 : 200;
0 ignored issues
show
Bug introduced by
The property created does not seem to exist in eZ\Publish\Core\REST\Server\Values\UserSession.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
31
        $visitor->setStatus($status);
32
33
        $visitor->setHeader('Content-Type', $generator->getMediaType('Session'));
34
        //@todo Needs refactoring, disabling certain headers should not be done this way
35
        $visitor->setHeader('Accept-Patch', false);
36
37
        $generator->startObjectElement('Session');
38
        $this->visitUserSessionAttributes($visitor, $generator, $data);
39
        $generator->endObjectElement('Session');
40
    }
41
42
    protected function visitUserSessionAttributes(Visitor $visitor, Generator $generator, UserSessionValue $data)
0 ignored issues
show
Unused Code introduced by
The parameter $visitor is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
43
    {
44
        $sessionHref = $this->router->generate('ezpublish_rest_deleteSession', array('sessionId' => $data->sessionId));
45
46
        $generator->startAttribute('href', $sessionHref);
47
        $generator->endAttribute('href');
48
49
        $generator->startValueElement('name', $data->sessionName);
50
        $generator->endValueElement('name');
51
52
        $generator->startValueElement('identifier', $data->sessionId);
53
        $generator->endValueElement('identifier');
54
55
        $generator->startValueElement('csrfToken', $data->csrfToken);
56
        $generator->endValueElement('csrfToken');
57
58
        $generator->startObjectElement('User', 'User');
59
        $generator->startAttribute(
60
            'href',
61
            $this->router->generate('ezpublish_rest_loadUser', array('userId' => $data->user->id))
62
        );
63
        $generator->endAttribute('href');
64
        $generator->endObjectElement('User');
65
    }
66
}
67