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.

MethodNotDefined   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 18
dl 0
loc 72
rs 10
c 2
b 0
f 0
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A format_message() 0 6 1
A __construct() 0 15 3
A get_method() 0 3 1
A get_instance() 0 3 1
A get_class() 0 3 1
1
<?php
2
3
/*
4
 * This file is part of the ICanBoogie package.
5
 *
6
 * (c) Olivier Laviale <[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 ICanBoogie\Prototype;
13
14
use BadMethodCallException;
15
use ICanBoogie\Accessor\AccessorTrait;
16
use Throwable;
17
18
use function assert;
19
use function get_class;
20
use function ICanBoogie\format;
21
use function is_object;
22
use function is_string;
23
24
/**
25
 * Exception thrown in attempt to access a method that is not defined.
26
 *
27
 * @property-read string $method The method that is not defined.
28
 * @property-read class-string $class The class of the instance on which the method was invoked.
29
 * @property-read object|null $instance Instance on which the method was invoked, or `null` if
30
 * only the class is available.
31
 */
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string.
Loading history...
32
class MethodNotDefined extends BadMethodCallException implements Exception
33
{
34
    /**
35
     * @uses get_method
36
     * @uses get_class
37
     * @uses get_instance
38
     */
39
    use AccessorTrait;
40
41
    /**
42
     * @var string
43
     */
44
    private $method;
45
46
    private function get_method(): string
47
    {
48
        return $this->method;
49
    }
50
51
    /**
52
     * @var class-string
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string.
Loading history...
53
     */
54
    private $class;
55
56
    private function get_class(): string
57
    {
58
        return $this->class;
59
    }
60
61
    /**
62
     * @var object|null
63
     */
64
    private $instance;
65
66
    private function get_instance(): ?object
67
    {
68
        return $this->instance;
69
    }
70
71
    /**
72
     * @inheritdoc
73
     *
74
     * @param string $method The method that is not defined.
75
     * @param class-string|object $class_or_instance The name of the class or one of its instances.
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string|object at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string|object.
Loading history...
76
     * @param string|null $message If `null` a message is formatted with $method and $class.
77
     */
78
    public function __construct(string $method, $class_or_instance, string $message = null, Throwable $previous = null)
79
    {
80
        $class = $class_or_instance;
81
82
        if (is_object($class_or_instance)) {
83
            $this->instance = $class_or_instance;
84
            $class = get_class($class_or_instance);
85
        }
86
87
        assert(is_string($class));
88
89
        $this->method = $method;
90
        $this->class = $class;
91
92
        parent::__construct($message ?: $this->format_message($method, $class), 0, $previous);
93
    }
94
95
    /**
96
     * @param class-string $class
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string.
Loading history...
97
     */
98
    private function format_message(string $method, string $class): string
99
    {
100
        return format('The method %method is not defined by the prototype of class %class.', [
101
102
            'method' => $method,
103
            'class' => $class
104
105
        ]);
106
    }
107
}
108