PublicApiAccess   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 23
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setOptions() 0 9 2
A auth() 0 5 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