Failed Conditions
Push — debug ( 1d31d3 )
by Bernhard
58:33 queued 54:52
created

CatCommandHandler::handle()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 20
rs 9.2
cc 4
eloc 10
nc 4
nop 2
1
<?php
2
3
/*
4
 * This file is part of the puli/cli package.
5
 *
6
 * (c) Bernhard Schussek <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Puli\Cli\Handler;
13
14
use Puli\Repository\Api\Resource\BodyResource;
15
use Puli\Repository\Api\ResourceRepository;
16
use Webmozart\Console\Api\Args\Args;
17
use Webmozart\Console\Api\IO\IO;
18
use Webmozart\PathUtil\Path;
19
20
/**
21
 * Handles the "cat" command.
22
 *
23
 * @since  1.0
24
 *
25
 * @author Stephan Wentz <[email protected]>
26
 */
27
class CatCommandHandler
28
{
29
    /**
30
     * @var ResourceRepository
31
     */
32
    private $repo;
33
34
    /**
35
     * @var string
36
     */
37
    private $currentPath = '/';
38
39
    /**
40
     * Creates the handler.
41
     *
42
     * @param ResourceRepository $repo The resource repository.
43
     */
44
    public function __construct(ResourceRepository $repo)
45
    {
46
        $this->repo = $repo;
47
    }
48
49
    /**
50
     * Handles the "ls" command.
51
     *
52
     * @param Args $args The console arguments.
53
     * @param IO   $io   The I/O.
54
     *
55
     * @return int The status code.
56
     */
57
    public function handle(Args $args, IO $io)
58
    {
59
        $path = Path::makeAbsolute($args->getArgument('path'), $this->currentPath);
60
61
        $resources = $this->repo->find($path);
62
63
        if (!count($resources)) {
64
            $io->errorLine(sprintf('No resources found for path %s', $path));
65
66
            return 1;
67
        }
68
69
        foreach ($resources as $resource) {
70
            if ($resource instanceof BodyResource) {
0 ignored issues
show
Bug introduced by
The class Puli\Repository\Api\Resource\BodyResource does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
71
                $io->writeLine($resource->getBody());
72
            }
73
        }
74
75
        return 0;
76
    }
77
}
78