Passed
Push — test ( 1ff34a...5f8c8d )
by Tom
02:50
created

PipelineContainer::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
/* this file is part of pipelines */
4
5
namespace Ktomk\Pipelines\Runner;
6
7
use Ktomk\Pipelines\File\Step;
8
9
/**
10
 * Class StepContainer
11
 *
12
 * @package Ktomk\Pipelines\Runner
13
 */
14
class PipelineContainer
15
{
16
    /**
17
     * @var Step
18
     */
19
    private $step;
20
21
    /**
22
     * @return PipelineContainer
23
     */
24 2
    public static function create(Step $step)
25
    {
26 2
        return new self($step);
27
    }
28
29
    /**
30
     * @param Step $step
31
     * @param string $prefix
32
     * @param string $project name
33
     *
34
     * @return string
35
     */
36 1
    public static function createName(Step $step, $prefix, $project)
37
    {
38 1
        return self::create($step)->generateName($prefix, $project);
39
    }
40
41
    /**
42
     * StepContainer constructor.
43
     *
44
     * @param Step $step
45
     */
46 2
    public function __construct(Step $step)
47
    {
48 2
        $this->step = $step;
49 2
    }
50
51
    /**
52
     * @param string $prefix
53
     * @param string $project name
54
     *
55
     * @return string
56
     */
57 2
    public function generateName($prefix, $project)
58
    {
59 2
        $step = $this->step;
60
61 2
        $idContainerSlug = preg_replace('([^a-zA-Z0-9_.-]+)', '-', $step->getPipeline()->getId());
62 2
        if ('' === $idContainerSlug) {
63 2
            $idContainerSlug = 'null';
64
        }
65 2
        $nameSlug = preg_replace(array('( )', '([^a-zA-Z0-9_.-]+)'), array('-', ''), $step->getName());
66 2
        if ('' === $nameSlug) {
67 2
            $nameSlug = 'no-name';
68
        }
69
70 2
        return $prefix . '-' . implode(
71 2
            '.',
72
            array(
73 2
                $step->getIndex() + 1,
74 2
                $nameSlug,
75 2
                trim($idContainerSlug, '-'),
76 2
                $project,
77
            )
78
        );
79
    }
80
}
81