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
Branch master (3b9792)
by Tomasz
01:41
created

AbstractTestCase::makeCallbackExtendsEnum()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 6
rs 10
1
<?php
2
declare(strict_types=1);
3
namespace Thunder\Platenum\Tests;
4
5
use PHPUnit\Framework\TestCase;
6
use Thunder\Platenum\Enum\AbstractCallbackEnum;
7
use Thunder\Platenum\Enum\AbstractConstantsEnum;
8
use Thunder\Platenum\Enum\AbstractDocblockEnum;
9
use Thunder\Platenum\Enum\AbstractStaticEnum;
10
use Thunder\Platenum\Enum\CallbackEnumTrait;
11
use Thunder\Platenum\Enum\ConstantsEnumTrait;
12
use Thunder\Platenum\Enum\DocblockEnumTrait;
13
use Thunder\Platenum\Enum\EnumTrait;
14
use Thunder\Platenum\Enum\StaticEnumTrait;
15
use Thunder\Platenum\Tests\Fake\FakeEnum;
16
17
/**
18
 * @author Tomasz Kowalczyk <[email protected]>
19
 */
20
abstract class AbstractTestCase extends TestCase
21
{
22
    /** @return FakeEnum */
23
    protected function makeRawEnum(array $members): string
24
    {
25
        $entries = [];
26
        foreach($members as $member => $value) {
27
            $entries[] = sprintf('%s => %s', '\''.$member.'\'', is_string($value) ? '\''.$value.'\'' : $value);
28
        }
29
30
        $class = $this->computeUniqueClassName('RawEnum');
31
        eval('final class '.$class.' implements \JsonSerializable {
0 ignored issues
show
introduced by
The use of eval() is discouraged.
Loading history...
32
            use '.EnumTrait::class.';
33
            private static function resolve(): array { return ['.implode(', ', $entries).']; }
34
        }');
35
36
        return $class;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $class returns the type string which is incompatible with the documented return type Thunder\Platenum\Tests\Fake\FakeEnum.
Loading history...
37
    }
38
39
    /** @return FakeEnum */
40
    protected function makeDocblockTraitEnum(array $members): string
41
    {
42
        $entries = [];
43
        foreach($members as $member => $value) {
44
            $entries[] = sprintf(' * @method static self %s()', $member);
45
        }
46
47
        $class = $this->computeUniqueClassName('DocblockTrait');
48
        eval('/**'."\n".implode("\n", $entries)."\n".'*/ final class '.$class.' { use '.DocblockEnumTrait::class.'; }');
0 ignored issues
show
introduced by
The use of eval() is discouraged.
Loading history...
49
50
        return $class;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $class returns the type string which is incompatible with the documented return type Thunder\Platenum\Tests\Fake\FakeEnum.
Loading history...
51
    }
52
53
    /** @return FakeEnum */
54
    protected function makeDocblockExtendsEnum(array $members): string
55
    {
56
        $entries = [];
57
        foreach($members as $member => $value) {
58
            $entries[] = sprintf(' * @method static self %s()', $member);
59
        }
60
61
        $class = $this->computeUniqueClassName('DocblockExtends');
62
        eval('/**'."\n".implode("\n", $entries)."\n".'*/ final class '.$class.' extends '.AbstractDocblockEnum::class.' {}');
0 ignored issues
show
introduced by
The use of eval() is discouraged.
Loading history...
63
64
        return $class;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $class returns the type string which is incompatible with the documented return type Thunder\Platenum\Tests\Fake\FakeEnum.
Loading history...
65
    }
66
67
    /** @return FakeEnum */
68
    protected function makeConstantsTraitEnum(array $members): string
69
    {
70
        $entries = [];
71
        foreach($members as $member => $value) {
72
            $entries[] = sprintf('private const %s = %s;', $member, is_string($value) ? '\''.$value.'\'' : $value);
73
        }
74
75
        $class = $this->computeUniqueClassName('ConstantsTrait');
76
        eval('final class '.$class.' implements \JsonSerializable { '.implode("\n", $entries).' use '.ConstantsEnumTrait::class.'; }');
0 ignored issues
show
introduced by
The use of eval() is discouraged.
Loading history...
77
78
        return $class;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $class returns the type string which is incompatible with the documented return type Thunder\Platenum\Tests\Fake\FakeEnum.
Loading history...
79
    }
80
81
    /** @return FakeEnum */
82
    protected function makeConstantsExtendsEnum(array $members): string
83
    {
84
        $entries = [];
85
        foreach($members as $member => $value) {
86
            $entries[] = sprintf('private const %s = %s;', $member, is_string($value) ? '\''.$value.'\'' : $value);
87
        }
88
89
        $class = $this->computeUniqueClassName('ConstantsExtends');
90
        eval('final class '.$class.' extends '.AbstractConstantsEnum::class.' { '.implode("\n", $entries).' }');
0 ignored issues
show
introduced by
The use of eval() is discouraged.
Loading history...
91
92
        return $class;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $class returns the type string which is incompatible with the documented return type Thunder\Platenum\Tests\Fake\FakeEnum.
Loading history...
93
    }
94
95
    /** @return FakeEnum */
96
    protected function makeStaticTraitEnum(array $members): string
97
    {
98
        $entries = [];
99
        foreach($members as $member => $value) {
100
            $entries[] = sprintf('%s => %s', '\''.$member.'\'', is_string($value) ? '\''.$value.'\'' : $value);
101
        }
102
103
        $class = $this->computeUniqueClassName('StaticTrait');
104
        eval('final class '.$class.' implements \JsonSerializable { private static $mapping = ['.implode(', ', $entries).']; use '.StaticEnumTrait::class.'; }');
0 ignored issues
show
introduced by
The use of eval() is discouraged.
Loading history...
105
106
        return $class;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $class returns the type string which is incompatible with the documented return type Thunder\Platenum\Tests\Fake\FakeEnum.
Loading history...
107
    }
108
109
    /** @return FakeEnum */
110
    protected function makeStaticExtendsEnum(array $members): string
111
    {
112
        $entries = [];
113
        foreach($members as $member => $value) {
114
            $entries[] = sprintf('%s => %s', '\''.$member.'\'', is_string($value) ? '\''.$value.'\'' : $value);
115
        }
116
117
        $class = $this->computeUniqueClassName('StaticExtends');
118
        eval('final class '.$class.' extends '.AbstractStaticEnum::class.' { protected static $mapping = ['.implode(', ', $entries).']; }');
0 ignored issues
show
introduced by
The use of eval() is discouraged.
Loading history...
119
120
        return $class;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $class returns the type string which is incompatible with the documented return type Thunder\Platenum\Tests\Fake\FakeEnum.
Loading history...
121
    }
122
123
    /** @return FakeEnum */
124
    protected function makeCallbackTraitEnum(array $members): string
0 ignored issues
show
Unused Code introduced by
The parameter $members is not used and could be removed. ( Ignorable by Annotation )

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

124
    protected function makeCallbackTraitEnum(/** @scrutinizer ignore-unused */ array $members): string

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
125
    {
126
        $class = $this->computeUniqueClassName('CallbackTrait');
127
        eval('final class '.$class.' implements \JsonSerializable { use '.CallbackEnumTrait::class.'; }');
0 ignored issues
show
introduced by
The use of eval() is discouraged.
Loading history...
128
129
        return $class;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $class returns the type string which is incompatible with the documented return type Thunder\Platenum\Tests\Fake\FakeEnum.
Loading history...
130
    }
131
132
    /** @return FakeEnum */
133
    protected function makeCallbackExtendsEnum(array $members): string
0 ignored issues
show
Unused Code introduced by
The parameter $members is not used and could be removed. ( Ignorable by Annotation )

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

133
    protected function makeCallbackExtendsEnum(/** @scrutinizer ignore-unused */ array $members): string

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
134
    {
135
        $class = $this->computeUniqueClassName('CallbackExtends');
136
        eval('final class '.$class.' extends '.AbstractCallbackEnum::class.' { }');
0 ignored issues
show
introduced by
The use of eval() is discouraged.
Loading history...
137
138
        return $class;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $class returns the type string which is incompatible with the documented return type Thunder\Platenum\Tests\Fake\FakeEnum.
Loading history...
139
    }
140
141
    protected function computeUniqueClassName(string $prefix): string
142
    {
143
        while(true === class_exists($class = $prefix.random_int(1, 1000000))) {
144
            continue;
145
        }
146
147
        return $class;
148
    }
149
}
150