Completed
Push — master ( 816b60...a0065d )
by Shcherbak
03:15
created

ComposerReview   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 77.78%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 0
cbo 4
dl 0
loc 53
ccs 14
cts 18
cp 0.7778
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 3 1
A getDescription() 0 3 1
A canProcess() 0 3 1
A process() 0 19 3
1
<?php
2
3
  namespace Funivan\Cs\Tools\Composer;
4
5
  use Funivan\Cs\FileTool\FileTool;
6
  use Funivan\Cs\Fs\File;
7
  use Funivan\Cs\Fs\FileFilter;
8
  use Funivan\Cs\Report\Report;
9
  use Symfony\Component\Process\Process;
10
11
  /**
12
   * @author Ivan Shcherbak <[email protected]> 2016
13
   */
14
  class ComposerReview implements FileTool {
15
16
    const NAME = 'composer_review';
17
18
19
    /**
20
     * @inheritdoc
21
     */
22 2
    public function getName() {
23 2
      return self::NAME;
24
    }
25
26
27
    /**
28
     * @inheritdoc
29
     */
30
    public function getDescription() {
31
      return 'Validate composer.json file';
32
    }
33
34
35
    /**
36
     * @inheritdoc
37
     */
38
    public function canProcess(File $file) {
39
      return (new FileFilter())->name(['!^composer.json$!'])->isValid($file);
40
    }
41
42
43
    /**
44
     * @inheritdoc
45
     */
46 2
    public function process(File $file, Report $report) {
47
48 2
      $process = new Process(sprintf('composer validate %s', $file->getPath()));
49 2
      $process->run();
50
51 2
      if ($process->isSuccessful()) {
52 1
        return;
53
      }
54
55
56 1
      $errorOutput = $process->getErrorOutput();
57 1
      preg_match('!Parse error on line (\d+):!', $errorOutput, $matchedLine);
58 1
      $line = 1;
59 1
      if (isset($matchedLine[1])) {
60 1
        $line = (int) $matchedLine[1];
61
      }
62
63 1
      $report->addMessage($file, $this, 'Invalid composer.json file format', $line);
64 1
    }
65
66
  }