Passed
Push — main ( 0ea815...bb79e1 )
by Chema
03:47 queued 19s
created

PhelConfig::setTempDir()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Phel\Config;
6
7
use JsonSerializable;
8
9
final class PhelConfig implements JsonSerializable
10
{
11
    public const SRC_DIRS = 'src-dirs';
12
13
    public const TEST_DIRS = 'test-dirs';
14
15
    public const VENDOR_DIR = 'vendor-dir';
16
17
    public const BUILD_CONFIG = 'out';
18
19
    public const ERROR_LOG_FILE = 'error-log-file';
20
21
    public const EXPORT_CONFIG = 'export';
22
23
    public const IGNORE_WHEN_BUILDING = 'ignore-when-building';
24
25
    public const NO_CACHE_WHEN_BUILDING = 'no-cache-when-building';
26
27
    public const KEEP_GENERATED_TEMP_FILES = 'keep-generated-temp-files';
28
29
    public const TEMP_DIR = 'temp-dir';
30
31
    public const FORMAT_DIRS = 'format-dirs';
32
33
    /** @var list<string> */
0 ignored issues
show
Bug introduced by
The type Phel\Config\list was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
34
    private array $srcDirs = ['src'];
35
36
    /** @var list<string> */
37
    private array $testDirs = ['tests'];
38
39
    private string $vendorDir = 'vendor';
40
41
    private string $errorLogFile = '/tmp/phel-error.log';
42
43
    private PhelExportConfig $exportConfig;
44
45
    private PhelBuildConfig $buildConfig;
46
47
    /** @var list<string> */
48
    private array $ignoreWhenBuilding = ['ignore-when-building.phel'];
49
50
    /** @var list<string> */
51
    private array $noCacheWhenBuilding = [];
52
53
    private bool $keepGeneratedTempFiles = false;
54
55
    private string $tempDir;
56
57
    /** @var list<string> */
58
    private array $formatDirs = ['src', 'tests'];
59
60 8
    public function __construct()
61
    {
62 8
        $this->exportConfig = new PhelExportConfig();
63 8
        $this->buildConfig = new PhelBuildConfig();
64 8
        $this->tempDir = sys_get_temp_dir() . '/phel';
65
    }
66
67
    /**
68
     * @param  list<string>  $list
69
     */
70 7
    public function setSrcDirs(array $list): self
71
    {
72 7
        $this->srcDirs = $list;
0 ignored issues
show
Documentation Bug introduced by
It seems like $list of type array is incompatible with the declared type Phel\Config\list of property $srcDirs.

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...
73
74 7
        return $this;
75
    }
76
77
    /**
78
     * @param  list<string>  $list
79
     */
80 1
    public function setTestDirs(array $list): self
81
    {
82 1
        $this->testDirs = $list;
0 ignored issues
show
Documentation Bug introduced by
It seems like $list of type array is incompatible with the declared type Phel\Config\list of property $testDirs.

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...
83
84 1
        return $this;
85
    }
86
87 5
    public function setVendorDir(string $dir): self
88
    {
89 5
        $this->vendorDir = $dir;
90
91 5
        return $this;
92
    }
93
94 1
    public function setExportConfig(PhelExportConfig $exportConfig): self
95
    {
96 1
        $this->exportConfig = $exportConfig;
97
98 1
        return $this;
99
    }
100
101 1
    public function setErrorLogFile(string $filepath): self
102
    {
103 1
        $this->errorLogFile = $filepath;
104
105 1
        return $this;
106
    }
107
108
    /**
109
     * @deprecated use `setBuildConfig(PhelBuildConfig)`
110
     */
111
    public function setOut(PhelBuildConfig $buildConfig): self
112
    {
113
        return $this->setBuildConfig($buildConfig);
114
    }
115
116 5
    public function setBuildConfig(PhelBuildConfig $buildConfig): self
117
    {
118 5
        $this->buildConfig = $buildConfig;
119
120 5
        return $this;
121
    }
122
123
    /**
124
     * @param  list<string>  $list
125
     */
126 5
    public function setIgnoreWhenBuilding(array $list): self
127
    {
128 5
        $this->ignoreWhenBuilding = $list;
0 ignored issues
show
Documentation Bug introduced by
It seems like $list of type array is incompatible with the declared type Phel\Config\list of property $ignoreWhenBuilding.

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...
129
130 5
        return $this;
131
    }
132
133 1
    public function setKeepGeneratedTempFiles(bool $flag): self
134
    {
135 1
        $this->keepGeneratedTempFiles = $flag;
136
137 1
        return $this;
138
    }
139
140 1
    public function setTempDir(string $dir): self
141
    {
142 1
        $this->tempDir = rtrim($dir, DIRECTORY_SEPARATOR);
143
144 1
        return $this;
145
    }
146
147
    /**
148
     * @param  list<string>  $list
149
     */
150 1
    public function setFormatDirs(array $list): self
151
    {
152 1
        $this->formatDirs = $list;
0 ignored issues
show
Documentation Bug introduced by
It seems like $list of type array is incompatible with the declared type Phel\Config\list of property $formatDirs.

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...
153
154 1
        return $this;
155
    }
156
157
    /**
158
     * @param  list<string>  $list
159
     */
160 4
    public function setNoCacheWhenBuilding(array $list): self
161
    {
162 4
        $this->noCacheWhenBuilding = $list;
0 ignored issues
show
Documentation Bug introduced by
It seems like $list of type array is incompatible with the declared type Phel\Config\list of property $noCacheWhenBuilding.

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...
163 4
        return $this;
164
    }
165
166 8
    public function jsonSerialize(): array
167
    {
168 8
        return [
169 8
            self::SRC_DIRS => $this->srcDirs,
170 8
            self::TEST_DIRS => $this->testDirs,
171 8
            self::VENDOR_DIR => $this->vendorDir,
172 8
            self::ERROR_LOG_FILE => $this->errorLogFile,
173 8
            self::BUILD_CONFIG => $this->buildConfig->jsonSerialize(),
174 8
            self::EXPORT_CONFIG => $this->exportConfig->jsonSerialize(),
175 8
            self::IGNORE_WHEN_BUILDING => $this->ignoreWhenBuilding,
176 8
            self::NO_CACHE_WHEN_BUILDING => $this->noCacheWhenBuilding,
177 8
            self::KEEP_GENERATED_TEMP_FILES => $this->keepGeneratedTempFiles,
178 8
            self::TEMP_DIR => $this->tempDir,
179 8
            self::FORMAT_DIRS => $this->formatDirs,
180 8
        ];
181
    }
182
}
183