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.

TransformerTrait   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 94.12%

Importance

Changes 0
Metric Value
wmc 9
c 0
b 0
f 0
lcom 1
cbo 0
dl 0
loc 55
ccs 16
cts 17
cp 0.9412
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A toEnv() 0 10 3
A toDots() 0 4 2
A dotTransformer() 0 17 4
1
<?php
2
3
/**
4
 * This file is part of the m1\vars library
5
 *
6
 * (c) m1 <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * @package     m1/vars
12
 * @version     1.1.0
13
 * @author      Miles Croxford <[email protected]>
14
 * @copyright   Copyright (c) Miles Croxford <[email protected]>
15
 * @license     http://github.com/m1/vars/blob/master/LICENSE
16
 * @link        http://github.com/m1/vars/blob/master/README.MD Documentation
17
 */
18
19
namespace M1\Vars\Traits;
20
21
/**
22
 * Vars transformer class for to*() functions
23
 *
24
 * @since 0.2.0
25
 */
26
trait TransformerTrait
27
{
28
    /**
29
     * Makes it so the content is available in getenv()
30
     */
31 1
    public function toEnv()
32
    {
33 1
        $dots = $this->toDots();
34
35 1
        if (is_array($dots)) {
36 1
            foreach ($dots as $dot_k => $dot_v) {
37 1
                putenv(sprintf('%s=%s', $dot_k, $dot_v));
38
            }
39
        }
40 1
    }
41
42
    /**
43
     * Converts the array into a flat dot notation array
44
     *
45
     * @param bool $flatten_array Flatten arrays into none existent keys
46
     *
47
     * @return array The dot notation array
48
     */
49 2
    public function toDots($flatten_array = true)
50
    {
51 2
        return (!is_null($this->content)) ? $this->dotTransformer($this->content, $flatten_array) : $this->content;
0 ignored issues
show
Bug introduced by
The property content 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...
52
    }
53
54
    /**
55
     * Converts the array into a flat dot notation array
56
     *
57
     * @param array  $content       The content array
58
     * @param bool   $flatten_array Flatten arrays into none existent keys
59
     * @param string $prefix        The prefix for the key
60
     *
61
     * @return array The dot notation array
62
     */
63 2
    private function dotTransformer($content, $flatten_array, $prefix = '')
64
    {
65 2
        $parsed = array();
66 2
        foreach ($content as $arr_k => $arr_v) {
67 2
            if (is_array($arr_v)) {
68 1
                if (!$flatten_array) {
69
                    $parsed[$prefix.$arr_k] = $arr_v;
70
                }
71
72 1
                $parsed = array_merge($parsed, $this->dotTransformer($arr_v, $flatten_array, $prefix.$arr_k."."));
73
            } else {
74 2
                $parsed[$prefix.$arr_k] = $arr_v;
75
            }
76
        }
77
78 2
        return $parsed;
79
    }
80
}
81