Completed
Push — master ( ebe931...c89697 )
by GBProd
02:12
created

Registry::mapProviders()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 9.6666
cc 1
eloc 5
nc 1
nop 1
crap 1
1
<?php
2
3
namespace GBProd\ElasticsearchDataProviderBundle\DataProvider;
4
5
/**
6
 * Registry for DataProvider
7
 * 
8
 * @author gbprod <[email protected]>
9
 */
10
class Registry
11
{
12
    /**
13
     * @var array<RegistryEntry>
14
     */
15
    private $entries = [];
16
    
17
    /**
18
     * Add a entry to the registry
19
     * 
20
     * @param RegistryEntry $entry
21
     */
22 2
    public function add(RegistryEntry $entry)
23
    {
24 2
        $this->entries[] = $entry;
25
        
26 2
        return $this;    
27
    }
28
    
29
    /**
30
     * Get entries for index and type
31
     * 
32
     * @param string $index
0 ignored issues
show
Documentation introduced by
Should the type for parameter $index not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
33
     * @param string $type
0 ignored issues
show
Documentation introduced by
Should the type for parameter $type not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
34
     * 
35
     * @return array<ProviderEntry>
36
     */
37 3
    public function get($index = null, $type = null)
38
    {
39 3
        return array_filter(
40 3
            $this->entries,
41 2
            function ($entry) use ($index, $type) {
42 2
                return $entry->match($index, $type);
43
            }
44 3
        );
45
    }
46
}