comparison vendor/symfony/yaml/Command/LintCommand.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents c2387f117808
children
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
89 if (!$filename) { 89 if (!$filename) {
90 if (!$stdin = $this->getStdin()) { 90 if (!$stdin = $this->getStdin()) {
91 throw new RuntimeException('Please provide a filename or pipe file content to STDIN.'); 91 throw new RuntimeException('Please provide a filename or pipe file content to STDIN.');
92 } 92 }
93 93
94 return $this->display($io, array($this->validate($stdin, $flags))); 94 return $this->display($io, [$this->validate($stdin, $flags)]);
95 } 95 }
96 96
97 if (!$this->isReadable($filename)) { 97 if (!$this->isReadable($filename)) {
98 throw new RuntimeException(sprintf('File or directory "%s" is not readable.', $filename)); 98 throw new RuntimeException(sprintf('File or directory "%s" is not readable.', $filename));
99 } 99 }
100 100
101 $filesInfo = array(); 101 $filesInfo = [];
102 foreach ($this->getFiles($filename) as $file) { 102 foreach ($this->getFiles($filename) as $file) {
103 $filesInfo[] = $this->validate(file_get_contents($file), $flags, $file); 103 $filesInfo[] = $this->validate(file_get_contents($file), $flags, $file);
104 } 104 }
105 105
106 return $this->display($io, $filesInfo); 106 return $this->display($io, $filesInfo);
117 }); 117 });
118 118
119 try { 119 try {
120 $this->getParser()->parse($content, Yaml::PARSE_CONSTANT | $flags); 120 $this->getParser()->parse($content, Yaml::PARSE_CONSTANT | $flags);
121 } catch (ParseException $e) { 121 } catch (ParseException $e) {
122 return array('file' => $file, 'line' => $e->getParsedLine(), 'valid' => false, 'message' => $e->getMessage()); 122 return ['file' => $file, 'line' => $e->getParsedLine(), 'valid' => false, 'message' => $e->getMessage()];
123 } finally { 123 } finally {
124 restore_error_handler(); 124 restore_error_handler();
125 } 125 }
126 126
127 return array('file' => $file, 'valid' => true); 127 return ['file' => $file, 'valid' => true];
128 } 128 }
129 129
130 private function display(SymfonyStyle $io, array $files) 130 private function display(SymfonyStyle $io, array $files)
131 { 131 {
132 switch ($this->format) { 132 switch ($this->format) {
139 } 139 }
140 } 140 }
141 141
142 private function displayTxt(SymfonyStyle $io, array $filesInfo) 142 private function displayTxt(SymfonyStyle $io, array $filesInfo)
143 { 143 {
144 $countFiles = count($filesInfo); 144 $countFiles = \count($filesInfo);
145 $erroredFiles = 0; 145 $erroredFiles = 0;
146 146
147 foreach ($filesInfo as $info) { 147 foreach ($filesInfo as $info) {
148 if ($info['valid'] && $this->displayCorrectFiles) { 148 if ($info['valid'] && $this->displayCorrectFiles) {
149 $io->comment('<info>OK</info>'.($info['file'] ? sprintf(' in %s', $info['file']) : '')); 149 $io->comment('<info>OK</info>'.($info['file'] ? sprintf(' in %s', $info['file']) : ''));
186 186
187 return; 187 return;
188 } 188 }
189 189
190 foreach ($this->getDirectoryIterator($fileOrDirectory) as $file) { 190 foreach ($this->getDirectoryIterator($fileOrDirectory) as $file) {
191 if (!in_array($file->getExtension(), array('yml', 'yaml'))) { 191 if (!\in_array($file->getExtension(), ['yml', 'yaml'])) {
192 continue; 192 continue;
193 } 193 }
194 194
195 yield $file; 195 yield $file;
196 } 196 }
227 \RecursiveIteratorIterator::LEAVES_ONLY 227 \RecursiveIteratorIterator::LEAVES_ONLY
228 ); 228 );
229 }; 229 };
230 230
231 if (null !== $this->directoryIteratorProvider) { 231 if (null !== $this->directoryIteratorProvider) {
232 return call_user_func($this->directoryIteratorProvider, $directory, $default); 232 return \call_user_func($this->directoryIteratorProvider, $directory, $default);
233 } 233 }
234 234
235 return $default($directory); 235 return $default($directory);
236 } 236 }
237 237
240 $default = function ($fileOrDirectory) { 240 $default = function ($fileOrDirectory) {
241 return is_readable($fileOrDirectory); 241 return is_readable($fileOrDirectory);
242 }; 242 };
243 243
244 if (null !== $this->isReadableProvider) { 244 if (null !== $this->isReadableProvider) {
245 return call_user_func($this->isReadableProvider, $fileOrDirectory, $default); 245 return \call_user_func($this->isReadableProvider, $fileOrDirectory, $default);
246 } 246 }
247 247
248 return $default($fileOrDirectory); 248 return $default($fileOrDirectory);
249 } 249 }
250 } 250 }