Passed
Branch master (15d1f5)
by Mehmet
02:07
created

PhpArray   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 96%

Importance

Changes 0
Metric Value
wmc 10
lcom 0
cbo 1
dl 0
loc 61
ccs 24
cts 25
cp 0.96
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A parse() 0 19 4
A checkFormat() 0 16 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