Completed
Pull Request — master (#1)
by Spencer
04:00
created

ScaleEngineCommandFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 6
nc 1
nop 3
1
<?php
2
namespace FloSports\ScaleEngine\CommandFactory;
3
4
use FloSports\ScaleEngine\Visitor\ScaleEngineRequestVisitor;
5
use Guzzle\Service\Command\Factory\ServiceDescriptionFactory;
6
use Guzzle\Service\Description\ServiceDescriptionInterface;
7
use Guzzle\Inflection\InflectorInterface;
8
9
/**
10
 * A Guzzle command factory that extends commands to work against the
11
 * ScaleEngine API.
12
 */
13
class ScaleEngineCommandFactory extends ServiceDescriptionFactory
14
{
15
    /** @type string The API secret used to sign requests. */
16
    private $_apiSecret;
17
18
    /**
19
     * Create the command factory for the ScaleEngine API requests.
20
     *
21
     * @param string $apiKey The API secret used to sign requests.
0 ignored issues
show
Bug introduced by
There is no parameter named $apiKey. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
22
     * @param ServiceDescriptionInterface $description Service description.
23
     * @param InflectorInterface $inflector Optional inflector to use if the
24
     *     command is not at first found.
25
     */
26
    public function __construct(
27
        $apiSecret,
28
        ServiceDescriptionInterface $description,
29
        InflectorInterface $inflector = null
30
    ) {
31
        parent::__construct($description, $inflector);
32
        $this->_apiSecret = $apiSecret;
33
    }
34
35
    /**
36
     * Create a Guzzle command using the applied service description.
37
     *
38
     * Extends the command created by the default ServiceDescriptionFactory
39
     * behavior with a request visitor that signs and encodes requests to
40
     * ScaleEngine's API.
41
     *
42
     * @see \FloSports\ScaleEngine\Visitor\ScaleEngineRequestVisitor
43
     * @param string $name The name of the command to create.
44
     * @param array $args The parameters to the command.
45
     * @return \Guzzle\Service\Command\CommandInterface|null The constructed
46
     *     command.
47
     */
48
    public function factory($name, array $args = [])
49
    {
50
        $command = parent::factory($name, $args);
51
        if (!$command) {
52
            return null;
53
        }
54
55
        $command->getRequestSerializer()->addVisitor(
56
            'scaleengineParameter',
57
            new ScaleEngineRequestVisitor($this->_apiSecret)
58
        );
59
60
        return $command;
61
    }
62
}
63