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.

ConjunctionInterceptor::invokeAssertions()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 7
c 1
b 0
f 0
nc 4
nop 2
dl 0
loc 12
rs 10
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
18
class ConjunctionInterceptor implements Assertable
19
{
20
    /**
21
     * @var Assertable[]
22
     */
23
    private $assertions;
24
25
    public function __construct(array $assertions)
26
    {
27
        $this->assertAssertions($assertions);
28
        $this->assertions = $assertions;
29
    }
30
31
    /**
32
     * Executes assertions based on all contained assertions.
33
     *
34
     * @param string $path
35
     * @param string $command
36
     * @return bool
37
     * @throws Exception
38
     */
39
    public function assert(string $path, string $command): bool
40
    {
41
        if ($this->invokeAssertions($path, $command)) {
42
            return true;
43
        }
44
        throw new Exception(
45
            sprintf(
46
                'Assertion failed in "%s"',
47
                $path
48
            ),
49
            1539625084
50
        );
51
    }
52
53
    /**
54
     * @param Assertable[] $assertions
55
     */
56
    private function assertAssertions(array $assertions)
57
    {
58
        foreach ($assertions as $assertion) {
59
            if (!$assertion instanceof Assertable) {
60
                throw new \InvalidArgumentException(
61
                    sprintf(
62
                        'Instance %s must implement Assertable',
63
                        get_class($assertion)
64
                    ),
65
                    1539624719
66
                );
67
            }
68
        }
69
    }
70
71
    /**
72
     * @param string $path
73
     * @param string $command
74
     * @return bool
75
     */
76
    private function invokeAssertions(string $path, string $command): bool
77
    {
78
        try {
79
            foreach ($this->assertions as $assertion) {
80
                if (!$assertion->assert($path, $command)) {
81
                    return false;
82
                }
83
            }
84
        } catch (Exception $exception) {
85
            return false;
86
        }
87
        return true;
88
    }
89
}
90