PublicApiAccess::setOptions()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
rs 9.6666
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
3
/**
4
 * This file is a part of nekland places api package
5
 *
6
 * (c) Nekland <[email protected]>
7
 *
8
 * For the full license, take a look to the LICENSE file
9
 * on the root directory of this project
10
 */
11
12
namespace Nekland\PlacesApi\Http\Auth;
13
14
use Nekland\BaseApi\Exception\MissingOptionException;
15
use Nekland\BaseApi\Http\Auth\AuthStrategyInterface;
16
use Nekland\BaseApi\Http\Event\RequestEvent;
17
18
class PublicApiAccess implements AuthStrategyInterface
19
{
20
    /**
21
     * @var array
22
     */
23
    private $options;
24
25
    public function setOptions(array $options)
26
    {
27
        if (empty($options['key'])) {
28
            throw new MissingOptionException(
29
                sprintf('You have to define the "key" option in order to make %s auth work.', get_class($this))
30
            );
31
        }
32
        $this->options = $options;
33
    }
34
35
    public function auth(RequestEvent $event)
36
    {
37
        $request = $event->getRequest();
38
        $request->setParameter('key', $this->options['key']);
39
    }
40
}
41