Issues (16)

src/Middleware/ErrorHandlingMiddleware.php (1 issue)

Labels
Severity
1
<?php
2
/**
3
 * @copyright Copyright (c) 2017 Julius Härtl <[email protected]>
4
 * @author    Julius Härtl <[email protected]>
5
 * @license   GNU AGPL version 3 or any later version
6
 *
7
 *  This program is free software: you can redistribute it and/or modify
8
 *  it under the terms of the GNU Affero General Public License as
9
 *  published by the Free Software Foundation, either version 3 of the
10
 *  License, or (at your option) any later version.
11
 *
12
 *  This program is distributed in the hope that it will be useful,
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *  GNU Affero General Public License for more details.
16
 *
17
 *  You should have received a copy of the GNU Affero General Public License
18
 *  along with this program. If not, see <http://www.gnu.org/licenses/>.
19
 */
20
21
namespace JuliusHaertl\PHPDocToRst\Middleware;
22
23
use Exception;
24
use JuliusHaertl\PHPDocToRst\ApiDocBuilder;
25
use phpDocumentor\Reflection\Middleware\Command;
26
use phpDocumentor\Reflection\Middleware\Middleware;
27
use phpDocumentor\Reflection\Php\File as FileElement;
28
29
/**
30
 * Class ErrorHandlingMiddleware.
31
 *
32
 * @ignore
33
 */
34
final class ErrorHandlingMiddleware implements Middleware
35
{
36
    private $apiDocBuilder;
37
38
    public function __construct(ApiDocBuilder $apiDocBuilder)
39
    {
40
        $this->apiDocBuilder = $apiDocBuilder;
41
    }
42
43
    /**
44
     * Executes this middleware class.
45
     *
46
     * @param Command  $command
47
     * @param callable $next
48
     *
49
     * @return object
50
     */
51
    public function execute(Command $command, callable $next): object
52
    {
53
        $filename = $command->getFile()->path();
0 ignored issues
show
The method getFile() does not exist on phpDocumentor\Reflection\Middleware\Command. It seems like you code against a sub-type of phpDocumentor\Reflection\Middleware\Command such as phpDocumentor\Reflection...tory\File\CreateCommand. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

53
        $filename = $command->/** @scrutinizer ignore-call */ getFile()->path();
Loading history...
54
        $this->apiDocBuilder->debug('Starting to parse file: '.$filename);
55
56
        try {
57
            return $next($command);
58
        } catch (Exception $e) {
59
            $this->apiDocBuilder->log('Unable to parse file "'.$filename.'", '.$e->getMessage());
60
            //Must Return empty file object
61
            return new FileElement(
62
                $command->getFile()->md5(),
63
                $filename
64
            );
65
        }
66
    }
67
}
68