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
Push — develop ( 4471cd...dae846 )
by Baptiste
03:11
created

Map::generate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 16
rs 9.9332
1
<?php
2
declare(strict_types = 1);
3
4
namespace Fixtures\Innmind\Immutable;
5
6
use Innmind\BlackBox\Set;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Fixtures\Innmind\Immutable\Set. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
7
use Innmind\Immutable\Map as Structure;
8
9
/**
10
 * {@inheritdoc}
11
 * @template I
12
 * @template J
13
 */
14
final class Map implements Set
15
{
16
    private $keyType;
17
    private $valueType;
18
    private $keys;
19
    private $values;
20
    private $sizes;
21
22
    public function __construct(
23
        string $keyType,
24
        string $valueType,
25
        Set $keys,
26
        Set $values,
27
        Set\Integers $sizes = null
0 ignored issues
show
Bug introduced by
The type Innmind\BlackBox\Set\Integers was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
28
    ) {
29
        $this->keyType = $keyType;
30
        $this->valueType = $valueType;
31
        $this->keys = $keys;
32
        $this->values = $values;
33
        $this->sizes = ($sizes ?? Set\Integers::between(0, 100))->take(100);
34
    }
35
36
    /**
37
     * @return Set<Structure<I, J>>
38
     */
39
    public static function of(
40
        string $keyType,
41
        string $valueType,
42
        Set $keys,
43
        Set $values,
44
        Set\Integers $sizes = null
45
    ): self {
46
        return new self($keyType, $valueType, $keys, $values, $sizes);
47
    }
48
49
    public function take(int $size): Set
50
    {
51
        $self = clone $this;
52
        $self->sizes = $this->sizes->take($size);
53
54
        return $self;
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60
    public function filter(callable $predicate): Set
61
    {
62
        throw new \LogicException('Map set can\'t be filtered, underlying sets must be filtered beforehand');
63
    }
64
65
    /**
66
     * @return \Generator<Set\Value<Structure<I, J>>>
67
     */
68
    public function values(): \Generator
69
    {
70
        $immutable = $this->keys->values()->current()->isImmutable() &&
71
            $this->values->values()->current()->isImmutable();
72
73
        foreach ($this->sizes->values() as $size) {
74
            if ($immutable) {
75
                yield Set\Value::immutable($this->generate($size->unwrap()));
0 ignored issues
show
Bug introduced by
The type Innmind\BlackBox\Set\Value was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
76
            } else {
77
                yield Set\Value::mutable(fn() => $this->generate($size->unwrap()));
78
            }
79
        }
80
    }
81
82
    private function generate(int $size): Structure
83
    {
84
        $map = Structure::of($this->keyType, $this->valueType);
85
        $keys = $this->keys->take($size)->values();
86
        $values = $this->values->take($size)->values();
87
88
        while ($map->size() < $size) {
89
            $map = ($map)(
90
                $keys->current()->unwrap(),
91
                $values->current()->unwrap(),
92
            );
93
            $keys->next();
94
            $values->next();
95
        }
96
97
        return $map;
98
    }
99
}
100