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.

Result::format()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 1
Metric Value
c 3
b 1
f 1
dl 0
loc 7
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: robbie
5
 * Date: 01/12/14
6
 * Time: 01:36
7
 */
8
9
namespace RobbieP\ZbarQrdecoder\Result;
10
11
12
use RobbieP\ZbarQrdecoder\Result\Parser\ParserXML;
13
14
class Result {
15
16
    const FORMAT_QR_CODE            = 'QR_CODE';
17
    const FORMAT_EAN_13             = 'EAN_13';
18
    const FORMAT_CODE_39            = 'CODE_39';
19
    const FORMAT_CODE_128           = 'CODE_128';
20
    const FORMAT_INTERLEAVED_2_5    = 'INTERLEAVED_2_5';
21
22
    public  $code;
23
    public  $text;
24
    public  $format;
25
26
    private static $prefix = [
27
        self::FORMAT_QR_CODE            => "QR-Code",
28
        self::FORMAT_EAN_13             => "EAN-13",
29
        self::FORMAT_CODE_39            => "CODE-39",
30
        self::FORMAT_CODE_128           => "CODE-128",
31
        self::FORMAT_INTERLEAVED_2_5    => "I2/5",
32
    ];
33
34
    protected $parser;
35
36
    /**
37
     * Pass in the raw result from the process
38
     * @param $result
39
     * @param $parser
40
     */
41
    function __construct($result, $parser = null) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
42
        $this->parser = !is_null($parser) ? $parser : new ParserXML();
43
        if(!empty($result))
44
        {
45
            $parsed = $this->parser->parse($result);
46
            // TODO: Tidy/Refactor this bit of code
47
            $this->text($parsed['text']);
48
            $this->format($parsed['format']);
49
        }
50
    }
51
52
    /**
53
     * Will determine what type of barcode and set the correct text response
54
     * @param $text
55
     */
56
    public function text($text)
57
    {
58
        $this->text = $text;
59
    }
60
61
    /**
62
     * Format of the bar code
63
     * @param $format
64
     */
65
    public function format($format)
66
    {
67
        $this->format = @array_search($format, self::$prefix);
68
        if($this->format) {
69
            $this->code = 200;
70
        }
71
    }
72
73
    /**
74
     * Just returns the text output
75
     * @return string
76
     */
77
    public function __toString()
78
    {
79
        if(!empty($this->text)) {
80
            return $this->text;
81
        }
82
        return 'No result';
83
    }
84
85
}