DetermineTargetVersionStage   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 10
c 1
b 0
f 0
dl 0
loc 27
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 21 5
1
<?php
2
3
namespace Nord\Lumen\Elasticsearch\Pipelines\Stages;
4
5
use Nord\Lumen\Elasticsearch\Pipelines\Payloads\ApplyMigrationPayload;
6
use League\Pipeline\StageInterface;
7
8
/**
9
 * Class DetermineTargetVersionStage
10
 * @package Nord\Lumen\Elasticsearch\Pipelines\Stages
11
 */
12
class DetermineTargetVersionStage implements StageInterface
13
{
14
15
    /**
16
     * @inheritDoc
17
     */
18
    public function __invoke($payload)
19
    {
20
        /** @var ApplyMigrationPayload $payload */
21
22
        $highestVersion = 0;
23
24
        foreach (scandir($payload->getIndexVersionsPath(), SCANDIR_SORT_NONE) as $file) {
25
            if ($file === '.' || $file === '..') {
26
                continue;
27
            }
28
29
            $version = (int)substr($file, 0, strpos($file, '.php'));
30
31
            if ($version > $highestVersion) {
32
                $highestVersion = $version;
33
                
34
                $payload->setTargetVersionFile($file);
35
            }
36
        }
37
38
        return $payload;
39
    }
40
}
41