ComposeFileCollection::setProjectName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace DockerCompose;
4
5
use Exception;
6
7
/**
8
 * DockerCompose\ComposeFileCollection
9
 */
10
class ComposeFileCollection
11
{
12
    /**
13
     * @var ComposeFiles
14
     */
15
    private $composeFiles = [];
16
17
    /**
18
     * @var projectName
19
     */
20
    private $projectName;
21
22
    /**
23
     * @param array of string or ComposeFile
24
     *
25
     * @throws \Exception When a composeFile definition is invalid
26
     */
27
    public function __construct()
28
    {
29
        $args = func_get_arg(0);
30
31
        if (!is_array($args)) {
32
            throw new \Exception('Invalid parameter "(' . gettype($args) . ')');
33
        }
34
35
        foreach ($args as $composeFile) {
36
            if ($composeFile instanceof ComposeFile) {
37
                $this->add($composeFile);
38
            } elseif (is_string($composeFile)) {
39
                $this->add(new ComposeFile($composeFile));
40 View Code Duplication
            } else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
41
                throw new \Exception(
42
                    'Invalid composeFile definition "(' . gettype(
43
                        $composeFile
44
                    ) . ') ' . var_export(
45
                        $composeFile,
46
                        true
47
                    ) . '"'
48
                );
49
            }
50
        }
51
    }
52
53
    /**
54
     * Return all composeFiles
55
     *
56
     * @return array
0 ignored issues
show
Documentation introduced by
Should the return type not be ComposeFiles?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
57
     */
58
    public function getAll()
59
    {
60
        return $this->composeFiles;
61
    }
62
63
    /**
64
     * Add a compose file
65
     */
66
    public function add(ComposeFile $composeFile)
67
    {
68
        $this->composeFiles[] = $composeFile;
69
        return $this;
70
    }
71
72
    /**
73
     * Set Project Name
74
     *
75
     * @param string $projectName
76
     *
77
     * @return ComposeFileCollection
78
     */
79
    public function setProjectName($projectName)
80
    {
81
        $this->projectName = $projectName;
0 ignored issues
show
Documentation Bug introduced by
It seems like $projectName of type string is incompatible with the declared type object<DockerCompose\projectName> of property $projectName.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
82
        return $this;
83
    }
84
85
    /**
86
     * Get Project Name
87
     *
88
     * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be projectName?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
89
     */
90
    public function getProjectName()
91
    {
92
        return $this->projectName;
93
    }
94
}
95