Passed
Branch master (4f2c04)
by Yaroslav
20:04
created

AbstractSymfonySecurityTest::serialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
/*
4
 *
5
 * (c) Yaroslav Honcharuk <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Yarhon\RouteGuardBundle\Security\Test;
12
13
/**
14
 * AbstractSymfonySecurityTest is a value object class for storing arguments for AuthorizationChecker::isGranted() authorization test.
15
 *
16
 * Note: we are using \Serializable interface here, because symfony/var-exporter does not
17
 * properly handles objects that have properties inherited from parent abstract class.
18
 * And since Symfony 4.2 symfony/cache uses symfony/var-exporter to store / retrieve values.
19
 *
20
 * @see \Symfony\Component\Security\Core\Authorization\AuthorizationChecker::isGranted
21
 *
22
 * @author Yaroslav Honcharuk <[email protected]>
23
 */
24
abstract class AbstractSymfonySecurityTest implements TestInterface, \Serializable
25
{
26
    /**
27
     * @var array
28
     */
29
    protected $attributes;
30
31
    /**
32
     * @var mixed
33
     */
34
    protected $subject;
35
36
    /**
37
     * @param array $attributes
38
     * @param mixed $subject
39
     */
40 60
    public function __construct(array $attributes, $subject = null)
41
    {
42 60
        $this->attributes = $attributes;
43 60
        $this->subject = $subject;
44 60
    }
45
46
    /**
47
     * @return array
48
     */
49 22
    public function getAttributes()
50
    {
51 22
        return $this->attributes;
52
    }
53
54
    /**
55
     * @return mixed
56
     */
57 16
    public function getSubject()
58
    {
59 16
        return $this->subject;
60
    }
61
62 8
    public function serialize()
63
    {
64 8
        return serialize([$this->attributes, $this->subject]);
65
    }
66
67 6
    public function unserialize($data)
68
    {
69 6
        list($attributes, $subject) = unserialize($data);
70 6
        $this->attributes = $attributes;
71 6
        $this->subject = $subject;
72 6
    }
73
}
74