Skip to content

Commit f3abbc0

Browse files
committed
[FrameworkBundle] fixed yaml:lint when yaml is not installed along side framwork-bundle
1 parent ef38bb2 commit f3abbc0

File tree

1 file changed

+36
-10
lines changed

1 file changed

+36
-10
lines changed

Command/LintCommand.php

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ class LintCommand extends Command
3030
private $parser;
3131
private $format;
3232
private $displayCorrectFiles;
33+
private $directoryIteratorProvider;
34+
private $isReadableProvider;
35+
36+
public function __construct($name = null, $directoryIteratorProvider = null, $isReadableProvider = null)
37+
{
38+
parent::__construct($name);
39+
40+
$this->directoryIteratorProvider = $directoryIteratorProvider;
41+
$this->isReadableProvider = $isReadableProvider;
42+
}
3343

3444
/**
3545
* {@inheritdoc}
@@ -170,14 +180,6 @@ private function getFiles($fileOrDirectory)
170180
}
171181
}
172182

173-
protected function getDirectoryIterator($directory)
174-
{
175-
return new \RecursiveIteratorIterator(
176-
new \RecursiveDirectoryIterator($directory, \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS),
177-
\RecursiveIteratorIterator::LEAVES_ONLY
178-
);
179-
}
180-
181183
private function getStdin()
182184
{
183185
if (0 !== ftell(STDIN)) {
@@ -201,8 +203,32 @@ private function getParser()
201203
return $this->parser;
202204
}
203205

204-
protected function isReadable($fileOrDirectory)
206+
private function getDirectoryIterator($directory)
205207
{
206-
return is_readable($fileOrDirectory);
208+
$default = function ($directory) {
209+
return new \RecursiveIteratorIterator(
210+
new \RecursiveDirectoryIterator($directory, \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS),
211+
\RecursiveIteratorIterator::LEAVES_ONLY
212+
);
213+
};
214+
215+
if (null !== $this->directoryIteratorProvider) {
216+
return call_user_func($this->directoryIteratorProvider, $directory, $default);
217+
}
218+
219+
return $default($directory);
220+
}
221+
222+
private function isReadable($fileOrDirectory)
223+
{
224+
$default = function ($fileOrDirectory) {
225+
return is_readable($fileOrDirectory);
226+
};
227+
228+
if (null !== $this->isReadableProvider) {
229+
return call_user_func($this->isReadableProvider, $fileOrDirectory, $default);
230+
}
231+
232+
return $default($fileOrDirectory);
207233
}
208234
}

0 commit comments

Comments
 (0)