GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

PharExtensionInterceptor   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 36
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A assert() 0 11 2
A baseFileContainsPharExtension() 0 8 2
1
<?php
2
declare(strict_types=1);
3
namespace TYPO3\PharStreamWrapper\Interceptor;
4
5
/*
6
 * This file is part of the TYPO3 project.
7
 *
8
 * It is free software; you can redistribute it and/or modify it under the terms
9
 * of the MIT License (MIT). For the full copyright and license information,
10
 * please read the LICENSE file that was distributed with this source code.
11
 *
12
 * The TYPO3 project - inspiring people to share!
13
 */
14
15
use TYPO3\PharStreamWrapper\Assertable;
16
use TYPO3\PharStreamWrapper\Exception;
17
use TYPO3\PharStreamWrapper\Manager;
18
19
class PharExtensionInterceptor implements Assertable
20
{
21
    /**
22
     * Determines whether the base file name has a ".phar" suffix.
23
     *
24
     * @param string $path
25
     * @param string $command
26
     * @return bool
27
     * @throws Exception
28
     */
29
    public function assert(string $path, string $command): bool
30
    {
31
        if ($this->baseFileContainsPharExtension($path)) {
32
            return true;
33
        }
34
        throw new Exception(
35
            sprintf(
36
                'Unexpected file extension in "%s"',
37
                $path
38
            ),
39
            1535198703
40
        );
41
    }
42
43
    /**
44
     * @param string $path
45
     * @return bool
46
     */
47
    private function baseFileContainsPharExtension(string $path): bool
48
    {
49
        $invocation = Manager::instance()->resolve($path);
50
        if ($invocation === null) {
51
            return false;
52
        }
53
        $fileExtension = pathinfo($invocation->getBaseName(), PATHINFO_EXTENSION);
54
        return strtolower($fileExtension) === 'phar';
0 ignored issues
show
Bug introduced by
It seems like $fileExtension can also be of type array; however, parameter $string of strtolower() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

54
        return strtolower(/** @scrutinizer ignore-type */ $fileExtension) === 'phar';
Loading history...
55
    }
56
}
57