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.

Parser   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 64
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 17 4
A extract() 0 18 4
1
<?php
2
3
/**
4
* This class contains the Parser Class
5
*
6
* PHP version 5.3+
7
*
8
* @package   Parser
9
* @author    Gabriel Alonso <[email protected]>
10
* @copyright 2015 Galonso
11
* @license   WTFPL - http://www.wtfpl.net/txt/copying/
12
* @link      https://github.com/g-alonso/FixedLengthHelper
13
*/
14
namespace Galonso\FixedLengthHelper;
15
use InvalidArgumentException;
16
use RuntimeException;
17
18
/**
19
* Parser
20
*
21
* @package   Parser
22
* @author    Gabriel Alonso <[email protected]>
23
* @copyright 2015 Galonso
24
* @license   WTFPL - http://www.wtfpl.net/txt/copying/
25
* @link      https://github.com/g-alonso/FixedLengthHelper
26
*/
27
class Parser
28
{
29
    /**
30
     * File Data
31
     * @var string
32
     */
33
    private $fileData;
34
35
    /**
36
     * Config
37
     * @var array
38
     */
39
    private $config = array();
40
41
    /**
42
     * Constructor
43
     *
44
     * @param string $file   file path
45
     * @param array  $config configuration array("name" => 22) // field name => size
46
     *
47
     * @throws Exception
48
     */
49
    public function __construct($file, $config)
50
    {
51
        if (!is_string($file) || !file_exists($file)) {
52
            throw new InvalidArgumentException(
53
                "Expects parameter 1 to be a valid file path"
54
            );
55
        }
56
57
        if (!is_readable($file)) {
58
            throw new RuntimeException("Unable to read file $file");
59
        }
60
61
        $fileData = file($file);
62
63
        $this->fileData = $fileData;
0 ignored issues
show
Documentation Bug introduced by
It seems like $fileData of type array is incompatible with the declared type string of property $fileData.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
64
        $this->config = $config;
65
    }
66
67
    /**
68
     * Extract
69
     *
70
     * @return Array
71
     */
72
    public function extract()
73
    {
74
        $return = array();
75
76
        foreach ($this->fileData as $line) {
0 ignored issues
show
Bug introduced by
The expression $this->fileData of type string is not traversable.
Loading history...
77
            if (!empty($line)) {
78
                $row = array();
79
                $start = 0;
80
                foreach ($this->config as $field => $length) {
81
                    $row[$field] = trim(substr($line, $start, $length));
82
                    $start += $length;
83
                }
84
                $return[] = $row;
85
            }
86
        }
87
88
        return $return;
89
    }
90
}