ExcludedOperationsStage::processStage()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 11
cts 11
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 8
nc 6
nop 1
crap 4
1
<?php
2
/**
3
 * Async sockets
4
 *
5
 * @copyright Copyright (c) 2015-2017, Efimov Evgenij <[email protected]>
6
 *
7
 * This source file is subject to the MIT license that is bundled
8
 * with this source code in the file LICENSE.
9
 */
10
namespace AsyncSockets\RequestExecutor\Pipeline;
11
12
use AsyncSockets\RequestExecutor\ExecutionContext;
13
use AsyncSockets\RequestExecutor\RequestExecutorInterface;
14
15
/**
16
 * Class ExcludedOperationsStage
17
 */
18
class ExcludedOperationsStage extends AbstractStage
19
{
20
    /**
21
     * Stages for processing successful descriptors
22
     *
23
     * @var PipelineStageInterface[]
24
     */
25
    private $stages;
26
27
    /**
28
     * AbstractStage constructor.
29
     *
30
     * @param RequestExecutorInterface $executor         Request executor
31
     * @param EventCaller              $eventCaller      Event caller
32
     * @param ExecutionContext         $executionContext Execution context
33
     * @param PipelineStageInterface[] $stages           Stages for success way
34
     */
35 68
    public function __construct(
36
        RequestExecutorInterface $executor,
37
        EventCaller $eventCaller,
38
        ExecutionContext $executionContext,
39
        array $stages
40
    ) {
41 68
        parent::__construct($executor, $eventCaller, $executionContext);
42 68
        $this->stages = $stages;
43 68
    }
44
45
    /** {@inheritdoc} */
46 54
    public function processStage(array $requestDescriptors)
47
    {
48 54
        $currentOperations = $requestDescriptors;
49 54
        foreach ($this->stages as $stage) {
50 54
            $currentOperations = $stage->processStage($currentOperations);
51 54
        }
52
53 28
        foreach ($requestDescriptors as $key => $descriptor) {
54 28
            if (in_array($descriptor, $currentOperations, true)) {
55 20
                unset($requestDescriptors[ $key]);
56 20
            }
57 28
        }
58
59 28
        return $requestDescriptors;
60
    }
61
}
62