Hoa central
Cs.php
Go to the documentation of this file.
1 <?php
2 
37 namespace Hoa\Devtools\Bin;
38 
39 use Hoa\Console;
40 use Hoa\Core;
41 
51 {
57  protected $options = [
58  ['dry-run', Console\GetOption::NO_ARGUMENT, 'd'],
59  ['diff', Console\GetOption::NO_ARGUMENT, 'D'],
60  ['help', Console\GetOption::NO_ARGUMENT, 'h'],
61  ['help', Console\GetOption::NO_ARGUMENT, '?']
62  ];
63 
64 
65 
71  public function main()
72  {
73  $dryRun = false;
74  $diff = false;
75 
76  while (false !== $c = $this->getOption($v)) {
77  switch ($c) {
78  case '__ambiguous':
79  $this->resolveOptionAmbiguity($v);
80 
81  break;
82 
83  case 'd':
84  $dryRun = true;
85 
86  break;
87 
88  case 'D':
89  $diff = true;
90 
91  break;
92 
93  case 'h':
94  case '?':
95  default:
96  return $this->usage();
97  }
98  }
99 
100  $this->parser->listInputs($path);
101 
102  if (empty($path)) {
103  return $this->usage();
104  }
105 
106  $phpCsFixer = Console\Processus::locate('php-cs-fixer');
107  $configurationFile = resolve(
108  'hoa://Library/Devtools/Resource/PHPCSFixer/ConfigurationFile.php'
109  );
110 
111  if (empty($phpCsFixer)) {
112  throw new Console\Exception('php-cs-fixer binary is not found.', 0);
113  }
114 
115  $arguments = ['fix', '--config-file' => $configurationFile];
116 
117  if (true === $dryRun) {
118  $arguments[] = '--dry-run';
119  }
120 
121  if (true === $diff) {
122  $arguments[] = '--diff';
123  }
124 
125  $arguments[] = $path;
126 
127  $processus = new Console\Processus($phpCsFixer, $arguments);
128  $processus->on('input', function () {
129  return false;
130  });
131  $processus->on('output', function (Core\Event\Bucket $bucket) {
132  echo $bucket->getData()['line'], "\n";
133 
134  return;
135  });
136  $processus->run();
137 
138  return;
139  }
140 
146  public function usage()
147  {
148  echo
149  'Usage : devtools:cs <options> path', "\n",
150  'Options :', "\n",
151  $this->makeUsageOptionsList([
152  'd' => 'Only shows which files would have been modified.',
153  'D' => 'Produce diff for each file.',
154  'help' => 'This help.'
155  ]), "\n";
156 
157  return;
158  }
159 }
160 
161 __halt_compiler();
162 Wrapper around `php-cs-fixer`.
makeUsageOptionsList(Array $definitions=[])
Definition: Kit.php:149
static locate($binary)
Definition: Processus.php:1133
getOption(&$optionValue, $short=null)
Definition: Kit.php:104
resolveOptionAmbiguity(Array $solutions)
Definition: Kit.php:190