Passed
Push — master ( 343fce...2eecbd )
by Victor
02:39
created

Context::getAttributes()   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
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Shoot\Shoot;
5
6
/**
7
 * Provides the context in which middleware processes a view.
8
 */
9
final class Context implements ContextInterface
10
{
11
    /** @var mixed[] */
12
    private $attributes;
13
14
    /**
15
     * @param mixed[] $attributes The attributes to assign to the context.
16
     */
17 15
    public function __construct(array $attributes = [])
18
    {
19 15
        $this->attributes = $attributes;
20 15
    }
21
22
    /**
23
     * @param string $name    The name of the attribute.
24
     * @param mixed  $default A default value is the attribute does not exist.
25
     *
26
     * @return mixed The value of the attribute, or the default if it does not exist.
27
     */
28 3
    public function getAttribute(string $name, $default = null)
29
    {
30 3
        return $this->attributes[$name] ?? $default;
31
    }
32
}
33