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.
Passed
Pull Request — master (#17)
by Oliver
01:48
created

AliasMap::findAllByAlias()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 1
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
namespace TYPO3\PharStreamWrapper\Resolver;
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
class AliasMap
16
{
17
    /**
18
     * @var AliasReference[]
19
     */
20
    private $references = [];
21
22
    /**
23
     * @param string $baseName
24
     * @param string $alias
25
     * @return bool
26
     */
27
    public function append(string $baseName, string $alias): bool
28
    {
29
        if ($baseName === '' || $alias === '') {
30
            return false;
31
        }
32
        if ($this->findFirstByBaseName($baseName) !== null) {
33
            return false;
34
        }
35
        $this->references[] = new AliasReference($baseName, $alias);
36
        return true;
37
    }
38
39
    /**
40
     * @param string $baseName
41
     * @return bool
42
     */
43
    public function purgeByBaseName(string $baseName): bool
44
    {
45
        if ($baseName === '') {
46
            return false;
47
        }
48
        $count = count($this->references);
49
        $this->references = array_filter(
50
            $this->references,
51
            function (AliasReference $reference) use ($baseName) {
52
                return $reference->getBaseName() !== $baseName;
53
            }
54
        );
55
        return count($this->references) < $count;
56
    }
57
58
    /**
59
     * @param string $baseName
60
     * @return null|AliasReference
61
     */
62
    public function findFirstByBaseName(string $baseName)
63
    {
64
        if ($baseName === '') {
65
            return null;
66
        }
67
        foreach (array_reverse($this->references) as $reference) {
68
            if ($reference->getBaseName() === $baseName) {
69
                return $reference;
70
            }
71
        }
72
        return null;
73
    }
74
75
    /**
76
     * @param string $alias
77
     * @return null|AliasReference
78
     */
79
    public function findLastByAlias(string $alias)
80
    {
81
        if ($alias === '') {
82
            return null;
83
        }
84
        foreach (array_reverse($this->references) as $reference) {
85
            if ($reference->getAlias() === $alias) {
86
                return $reference;
87
            }
88
        }
89
        return null;
90
    }
91
92
    /**
93
     * @param string $alias
94
     * @return AliasReference[]
95
     */
96
    public function findAllByAlias(string $alias): array
97
    {
98
        if ($alias === '') {
99
            return [];
100
        }
101
        return array_filter(
102
            $this->references,
103
            function (AliasReference $reference) use ($alias) {
104
                return $reference->getAlias() === $alias;
105
            }
106
        );
107
    }
108
}
109