Transpose   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 0
dl 0
loc 29
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B __invoke() 0 26 7
1
<?php
2
3
namespace Spatie\CollectionMacros\Macros;
4
5
use Illuminate\Support\Collection;
6
7
/**
8
 * Transpose an array.
9
 *
10
 * @mixin \Illuminate\Support\Collection
11
 *
12
 * @return \Illuminate\Support\Collection
13
 *
14
 * @throws \LengthException
15
 */
16
class Transpose
17
{
18
    public function __invoke()
19
    {
20
        return function (): Collection {
21
            if ($this->isEmpty()) {
0 ignored issues
show
Bug introduced by
The method isEmpty() does not seem to exist on object<Spatie\CollectionMacros\Macros\Transpose>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
22
                return new static();
23
            }
24
25
            $firstItem = $this->first();
0 ignored issues
show
Bug introduced by
The method first() does not seem to exist on object<Spatie\CollectionMacros\Macros\Transpose>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
26
27
            $expectedLength = is_array($firstItem) || $firstItem instanceof Countable ? count($firstItem) : 0;
0 ignored issues
show
Bug introduced by
The class Spatie\CollectionMacros\Macros\Countable does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
28
29
            array_walk($this->items, function ($row) use ($expectedLength) {
0 ignored issues
show
Bug introduced by
The property items does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
30
                if ((is_array($row) || $row instanceof Countable) && count($row) !== $expectedLength) {
0 ignored issues
show
Bug introduced by
The class Spatie\CollectionMacros\Macros\Countable does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
31
                    throw new \LengthException("Element's length must be equal.");
32
                }
33
            });
34
35
            $items = array_map(function (...$items) {
36
                return new static($items);
0 ignored issues
show
Unused Code introduced by
The call to Transpose::__construct() has too many arguments starting with $items.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
37
            }, ...array_map(function ($items) {
38
                return $this->getArrayableItems($items);
0 ignored issues
show
Bug introduced by
The method getArrayableItems() does not seem to exist on object<Spatie\CollectionMacros\Macros\Transpose>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
39
            }, array_values($this->items)));
40
41
            return new static($items);
0 ignored issues
show
Unused Code introduced by
The call to Transpose::__construct() has too many arguments starting with $items.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
42
        };
43
    }
44
}
45