11<?php
22
3+ declare (strict_types=1 );
4+
35namespace PLUS \GrumPHPBomTask ;
46
7+ use Symfony \Component \Finder \SplFileInfo ;
58use GrumPHP \Runner \TaskResult ;
69use GrumPHP \Runner \TaskResultInterface ;
710use GrumPHP \Task \Config \ConfigOptionsResolver ;
1518
1619final class BomFixerTask implements TaskInterface
1720{
18- /** @var TaskConfigInterface */
19- private $ config ;
21+ private EmptyTaskConfig |TaskConfigInterface $ config ;
2022
2123 public function __construct ()
2224 {
@@ -63,20 +65,19 @@ public function run(ContextInterface $context): TaskResultInterface
6365
6466 if (is_file ('./vendor/bin/fixbom ' )) {
6567 $ fixCommand = './vendor/bin/fixbom ' ;
68+ } elseif (is_file ('./bin/fixbom ' )) {
69+ $ fixCommand = './bin/fixbom ' ;
6670 } else {
67- if (is_file ('./bin/fixbom ' )) {
68- $ fixCommand = './bin/fixbom ' ;
69- } else {
70- $ fixCommand = 'fixbom ' ;
71- }
71+ $ fixCommand = 'fixbom ' ;
7272 }
73+
7374 $ shouldGetFixedLog = [];
74- /** @var \Symfony\Component\Finder\ SplFileInfo $file */
75+ /** @var SplFileInfo $file */
7576 foreach ($ files as $ file ) {
7677 $ execFile = $ file ->getPathname ();
7778 if ($ this ->isFileWithBOM ($ execFile )) {
7879 $ shouldGetFixedLog [] = $ execFile . ' has BOM and should be fixed ' ;
79- $ fixCommand .= ' \'' . $ execFile . '\'' ;
80+ $ fixCommand .= " ' " . $ execFile . " ' " ;
8081 }
8182 }
8283
@@ -86,6 +87,7 @@ public function run(ContextInterface $context): TaskResultInterface
8687 . $ fixCommand ;
8788 return TaskResult::createFailed ($ this , $ context , $ errorMessage );
8889 }
90+
8991 return TaskResult::createPassed ($ this , $ context );
9092 }
9193
@@ -98,9 +100,14 @@ private function fileInfoSearch(string $filename, string $search): bool
98100 {
99101 $ output = [];
100102 exec ('file ' . '" ' . $ filename . '" ' , $ output , $ returnVar );
101- if ($ returnVar === 0 && ! empty ( $ output [ 0 ]) && strpos ( $ output [ 0 ], $ search ) ! == false ) {
102- return true ;
103+ if ($ returnVar ! == 0 ) {
104+ return false ;
103105 }
104- return false ;
106+
107+ if (empty ($ output [0 ])) {
108+ return false ;
109+ }
110+
111+ return str_contains ($ output [0 ], $ search );
105112 }
106113}
0 commit comments