Completed
Pull Request — master (#19)
by Sullivan
03:48
created

DependsCommandWrapper   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
c 2
b 0
f 0
lcom 1
cbo 5
dl 0
loc 51
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 1
A dependsOutput() 0 13 2
1
<?php
2
3
namespace SLLH\ComposerVersionsCheck;
4
5
use Composer\Command\DependsCommand;
6
use Composer\Composer;
7
use Composer\DependencyResolver\Pool;
8
use Composer\IO\ConsoleIO;
9
use Composer\Package\PackageInterface;
10
use Symfony\Component\Console\Helper\HelperSet;
11
use Symfony\Component\Console\Input\ArrayInput;
12
use Symfony\Component\Console\Input\StringInput;
13
use Symfony\Component\Console\Output\BufferedOutput;
14
use Symfony\Component\Console\Output\OutputInterface;
15
16
/**
17
 * Depends command wrapper class to get needed output.
18
 *
19
 * @author Sullivan Senechal <[email protected]>
20
 */
21
final class DependsCommandWrapper
22
{
23
    /**
24
     * @var OutputInterface
25
     */
26
    private $output;
27
28
    private $composer;
29
30
    /**
31
     * @var DependsCommand
32
     */
33
    private $dependsCommand;
0 ignored issues
show
Unused Code introduced by
The property $dependsCommand is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
34
35
    /**
36
     * @param Composer $composer
37
     * @param bool     $decoratedOutput
38
     */
39
    public function __construct(Composer $composer, $decoratedOutput = false)
40
    {
41
        // TODO: Pass the repository instead
42
        $this->composer = $composer;
43
44
        //$this->dependsCommand = new DependsCommand();
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
45
        //$this->dependsCommand->setComposer($composer);
0 ignored issues
show
Unused Code Comprehensibility introduced by
78% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
46
47
        $this->output = new BufferedOutput();
48
        $this->output->setDecorated($decoratedOutput);
49
50
        //$this->dependsCommand->setIO(new ConsoleIO(new StringInput('depends'), $this->output, new HelperSet()));
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
51
    }
52
53
    /**
54
     * @param PackageInterface $package
55
     *
56
     * @return string[] The output, array of lines.
57
     */
58
    public function dependsOutput(PackageInterface $package)
59
    {
60
        $pool = new Pool();
61
        $pool->addRepository($this->composer->getRepositoryManager()->getLocalRepository());
62
63
        $output = array();
64
        $packages = $pool->whatProvides($package->getName());
65
        foreach ($packages as $dependent) {
66
            array_push($output, sprintf('    Required by %s (%s)', $dependent->getName(), '?'));
67
        }
68
69
        return $output;
70
    }
71
}
72