Completed
Push — master ( 0f2252...15d1f5 )
by Mehmet
02:04
created

PhpArray::checkFormat()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 9
cts 9
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 9
nc 6
nop 0
crap 4
1
<?php
2
declare(strict_types=1);
3
4
namespace Selami\Entity\Parser;
5
6
use Selami\Entity\Interfaces\ParserInterface;
7
use UnexpectedValueException;
8
use Selami\Entity\Exception\FileNotFoundException;
9
10
11
/**
12
 * Array Parser
13
 * @package Selami\Entity\Parser
14
 */
15
class PhpArray implements ParserInterface
16
{
17
    protected $schemaConfig;
18
19
    /**
20
     * Config constructor.
21
     * @param string $schemaConfig
22
     * @throws FileNotFoundException
23
     */
24 6
    public function __construct(string $schemaConfig)
25
    {
26 6
        if (!file_exists($schemaConfig)) {
27 1
            $message = sprintf('File: %s not found. please provide full path for file names', $schemaConfig);
28 1
            throw new FileNotFoundException($message);
29
        }
30 5
        $this->schemaConfig =  $schemaConfig;
31 5
    }
32
33
    /**
34
     * {@inheritDoc}
35
     */
36 3
    public function parse()
37
    {
38
        //$errorReportingValue = ini_get('error_reporting');
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
39 3
        //error_reporting(-1);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
40 1
        try {
41
            $schema = require $this->schemaConfig;
42
        } catch (\Exception $e) {
43 1
            throw new UnexpectedValueException($e->getMessage());
44 1
        } catch (\Error $e) {
45
            throw new UnexpectedValueException($e->getMessage());
46 2
        }
47 1
        finally {
48
           // error_reporting($errorReportingValue);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
49
        }
50 1
        if (!is_array($schema)) {
51
            throw new UnexpectedValueException('Config file does not return an array.');
52
        }
53
        return $schema;
54
    }
55
56 2
    /**
57
     * {@inheritDoc}
58
     */
59 2
    public function checkFormat()
60 1
    {
61 1
        try {
62 1
            $schema = require $this->schemaConfig;
63 1
            if (!is_array($schema)) {
64 1
                return false;
65 1
            }
66 1
            return true;
67
        } catch (\Exception $e) {
68 1
            // will return false
69
        } catch (\Error $e) {
70
            // will return false
71
        }
72
        return false;
73
74
    }
75
}
76