ArrayFileReader::loadArray()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 7
rs 10
1
<?php
2
3
    namespace rAPId\Data;
4
5
    class ArrayFileReader
6
    {
7
        private $filename;
8
9
        public function __construct($filename) {
10
            $this->filename = $filename;
11
        }
12
13
        public function loadArray() {
14
            $data = [];
15
            if (file_exists($this->filename)) {
16
                $data = $this->readArrayFromFile($this->filename);
17
            }
18
19
            return $data;
20
        }
21
22
        /**
23
         * @param string $filename
24
         *
25
         * @return array
26
         */
27
        private function readArrayFromFile($filename) {
28
            // Use output buffer to avoid any unwanted side-effects
29
            ob_start();
30
            $array = include "$filename";
31
            ob_end_clean();
32
33
            return $array;
34
        }
35
36
    }