1 | <?php |
||
29 | class ConcernedAboutSeparation extends AbstractExercise implements ExerciseInterface, CliExercise, SelfCheck |
||
30 | { |
||
31 | use TemporaryDirectoryTrait; |
||
32 | |||
33 | /** |
||
34 | * @var Filesystem |
||
35 | */ |
||
36 | private $filesystem; |
||
37 | |||
38 | /** |
||
39 | * @var Generator |
||
40 | */ |
||
41 | private $faker; |
||
42 | |||
43 | /** |
||
44 | * @var Parser |
||
45 | */ |
||
46 | private $parser; |
||
47 | |||
48 | /** |
||
49 | * @param Filesystem $filesystem |
||
50 | * @param Generator $faker |
||
51 | * @param Parser $parser |
||
52 | */ |
||
53 | public function __construct(Filesystem $filesystem, Generator $faker, Parser $parser) |
||
59 | |||
60 | /** |
||
61 | * @return string |
||
62 | */ |
||
63 | public function getName() |
||
67 | |||
68 | /** |
||
69 | * @return string |
||
70 | */ |
||
71 | public function getDescription() |
||
75 | |||
76 | /** |
||
77 | * @return array |
||
78 | */ |
||
79 | public function getArgs() |
||
80 | { |
||
81 | $folder = $this->getTemporaryPath(); |
||
82 | |||
83 | $files = [ |
||
84 | "learnyouphp.dat", |
||
85 | "learnyouphp.txt", |
||
86 | "learnyouphp.sql", |
||
87 | "txt", |
||
88 | "sql", |
||
89 | "api.html", |
||
90 | "html", |
||
91 | "README.md", |
||
92 | "CHANGELOG.md", |
||
93 | "LICENCE.md", |
||
94 | "md", |
||
95 | "data.json", |
||
96 | "json", |
||
97 | "data.dat", |
||
98 | "words.dat", |
||
99 | "w00t.dat", |
||
100 | "w00t.txt", |
||
101 | "wrrrrongdat", |
||
102 | "dat", |
||
103 | ]; |
||
104 | |||
105 | $this->filesystem->mkdir($folder); |
||
106 | array_walk($files, function ($file) use ($folder) { |
||
107 | $this->filesystem->dumpFile(sprintf('%s/%s', $folder, $file), ''); |
||
108 | }); |
||
109 | |||
110 | $ext = ''; |
||
111 | while ($ext === '') { |
||
112 | $index = array_rand($files); |
||
113 | $ext = pathinfo($files[$index], PATHINFO_EXTENSION); |
||
114 | } |
||
115 | |||
116 | return [$folder, $ext]; |
||
117 | } |
||
118 | |||
119 | /** |
||
120 | * @return SolutionInterface |
||
121 | */ |
||
122 | public function getSolution() |
||
126 | |||
127 | /** |
||
128 | * @return null |
||
129 | */ |
||
130 | public function tearDown() |
||
134 | |||
135 | /** |
||
136 | * @param Input $input |
||
137 | * @return ResultInterface |
||
138 | */ |
||
139 | public function check(Input $input) |
||
157 | |||
158 | /** |
||
159 | * @return ExerciseType |
||
160 | */ |
||
161 | public function getType() |
||
165 | } |
||
166 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.