Code Duplication    Length = 15-34 lines in 3 locations

src/anyURI.php 1 location

@@ 10-33 (lines=24) @@
7
 * Its value space includes the URIs defined by RFCs 2396 and 2732, but its lexical space doesn't require the character
8
 * escapes needed to include non-ASCII characters in a URIs.
9
 */
10
class anyURI extends SimpleTypeBase
11
{
12
    /**
13
     * Construct
14
     *
15
     * @param mixed $value
16
     */
17
    public function __construct($value)
18
    {
19
        $this->whiteSpace = "collapse";
20
        parent::__construct($value);
21
    }
22
    // TODO: Relative URIs aren't absolutized by the W3C XML Schema.
23
    // The Recommendation states that "it is impractical for processors to check that a value is
24
    // a context-appropriate URI reference," thus freeing schema processors from having to validate
25
    // the correctness of the URI.
26
    // But i think we should.
27
    protected function isValid($v)
28
    {
29
        if (!is_scalar($v) && !is_string($v)) {
30
            throw new \InvalidArgumentException("you must assign a valid uri to anyURI " . __CLASS__);
31
        }
32
    }
33
}
34

src/base64Binary.php 1 location

@@ 9-42 (lines=34) @@
6
 * The value space of xsd:base64Binary is the set of arbitrary binary contents.
7
 * Its lexical space is the same set after base64 coding. This coding is described in Section 6.8 of RFC 2045.
8
 */
9
class base64Binary extends SimpleTypeBase
10
{
11
    /**
12
     * Construct
13
     *
14
     * @param mixed $value
15
     */
16
    public function __construct($value)
17
    {
18
        $this->whiteSpace = "collapse";
19
        // In base64 encoding, the character set is [A-Z, a-z, 0-9, and + /].
20
        // If the rest length is less than 4, the string is padded with '=' characters.
21
        // ^([A-Za-z0-9+/]{4})* means the string starts with 0 or more base64 groups
22
        // ([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)$
23
        // means the string ends in one of three forms: [A-Za-z0-9+/]{4}, [A-Za-z0-9+/]{3}= or [A-Za-z0-9+/]{2}==
24
        //$this->pattern = "/^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)$/";
25
        parent::__construct($value);
26
    }
27
    // RFC 2045 describes the transfer of binary contents over text-based mail systems.
28
    // It imposes a line break at least every 76 characters to avoid the inclusion of
29
    // arbitrary line breaks by the mail systems. Sending base64 content without line breaks is
30
    // nevertheless a common usage for applications such as SOAP and the W3C XML Schema Working Group.
31
    // After a request from other W3C Working Groups, the W3C XML Schema Working Group decided to
32
    // remove the obligation to include these line breaks from the constraints on the lexical space.
33
    // (This decision was made after the publication of the W3C XML Schema Recommendation.
34
    // It is now noted in the errata.)
35
    //TODO: we could probably add more checks to a base64 encoded string see commented pattern
36
    protected function isValid($v)
37
    {
38
        if (!is_scalar($v) && !is_string($v)) {
39
            throw new \InvalidArgumentException("you must assign a valid value to base64Binary " . __CLASS__);
40
        }
41
    }
42
}
43

src/decimal.php 1 location

@@ 16-30 (lines=15) @@
13
 * Its lexical space allows any number of insignificant leading and trailing zeros (after the decimal point).
14
 * @package AlgoWeb\xsdTypes
15
 */
16
class decimal extends SimpleTypeBase
17
{
18
    public function __construct($value)
19
    {
20
        $this->whiteSpace = "replace";
21
        parent::__construct($value);
22
    }
23
24
    protected function isValid($v)
25
    {
26
        if (!is_numeric($v)) {
27
            throw new \InvalidArgumentException("failed to provide numeric value " . __CLASS__);
28
        }
29
    }
30
}
31