Types   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 25
ccs 9
cts 9
cp 1
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A exportToArray() 0 23 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace drupol\ComposerPackages\Exporter;
6
7
final class Types extends Exporter
8
{
9 2
    public function exportToArray(): array
10
    {
11 2
        $data = $this->getEvent()->getComposer()->getLocker()->getLockData();
12
13 2
        $packagesData = array_merge(
14 2
            $data['packages'],
15 2
            $data['packages-dev']
16
        );
17
18
        // out of the box composer supported types.
19
        $types = [
20 2
            'library' => [],
21
            'project' => [],
22
            'metapackage' => [],
23
            'composer-plugin' => [],
24
        ];
25
26 2
        foreach ($packagesData as $package) {
27 2
            $types[$package['type']][] = $package;
28
        }
29
30 2
        return [
0 ignored issues
show
Bug Best Practice introduced by
The expression return array('types' => $types) returns the type array<string,array<string,array>> which is incompatible with the return type mandated by drupol\ComposerPackages\...erface::exportToArray() of string[].

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
31
            'types' => $types,
32
        ];
33
    }
34
}
35