Completed
Pull Request — 1.x (#5)
by Dorian
01:32
created

BoolParser::parse()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.2
c 0
b 0
f 0
cc 4
eloc 8
nc 3
nop 1
1
<?php
2
namespace MetaHydrator\Parser;
3
4
use MetaHydrator\Exception\ParsingException;
5
6
/*
0 ignored issues
show
Unused Code Comprehensibility introduced by
36% 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...
7
 * An implementation of ParserInterface used to parse a boolean value.
8
 * Values allowed are true, "true", 1, "1", "yes", "on", false, "false", 0, "0", "no", "off"
9
 */
10
class BoolParser extends AbstractParser
11
{
12
    /**
13
     * @param $rawValue
14
     * @return bool|null
15
     *
16
     * @throws ParsingException
17
     */
18
    public function parse($rawValue)
19
    {
20
        if ($rawValue === null || $rawValue === '') {
21
            return null;
22
        } else {
23
            $value = filter_var($rawValue, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
24
            if ($value === null) {
25
                $this->throw();
26
            }
27
            return $value;
28
        }
29
    }
30
}
31