Collection::convert()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 12
rs 9.4285
cc 3
eloc 8
nc 3
nop 3
1
<?php
2
3
/**
4
 * @author Ben Rowe <[email protected]>
5
 * @license    http://www.opensource.org/licenses/mit-license.html MIT License
6
 */
7
8
namespace Benrowe\Laravel\Config\Modifiers;
9
10
use Benrowe\Laravel\Config\Modifiers\Modifier;
11
use Illuminate\Support\Collection as BaseCollection;
12
13
/**
14
 * Modifier collection
15
 *
16
 * @package Benrowe\Laravel\Config\Modifiers
17
 */
18
class Collection extends BaseCollection
19
{
20
    /**
21
     * @var array list of keys that have been modified
22
     */
23
    private $keys = [];
24
    
25
    /**
26
     * Convert the value based on the supplied modifiers
27
     *
28
     * @param  string $key       [description]
29
     * @param  mixed $value     [description]
30
     * @param  string $direction [description]
31
     * @return mixed            [description]
32
     */
33
    public function convert($key, $value, $direction = Modifier::DIRECTION_TO)
34
    {
35
        $convertMethod = 'convert'.ucfirst($direction);
36
        $canMethod = 'canHandle'.ucfirst($direction);
37
        foreach ($this->items as $modifier) {
38
            if ($modifier->$canMethod($value)) {
39
                $this->keys[] = $key;
40
                return $modifier->$convertMethod($value);
41
            }
42
        }
43
        return $value;
44
    }
45
}
46