LibxmlTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 20
c 2
b 0
f 0
dl 0
loc 52
ccs 13
cts 13
cp 1
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setLibxml() 0 14 2
A getLibxml() 0 3 1
A getDefaultLibxmlConfig() 0 11 1
1
<?php
2
/**
3
 * Copyright (c) 2010–2019 Ryan Parman <http://ryanparman.com>.
4
 * Copyright (c) 2016–2019 Contributors.
5
 *
6
 * http://opensource.org/licenses/Apache2.0
7
 */
8
9
declare(strict_types=1);
10
11
namespace SimplePie\UtilityPack\Mixin;
12
13
/**
14
 * Shared code for working with configurable libxml settings.
15
 */
16
trait LibxmlTrait
17
{
18
    /**
19
     * Bitwise libxml options to use for parsing XML.
20
     *
21
     * @var int
22
     */
23
    protected $libxml;
0 ignored issues
show
Coding Style introduced by
Protected member variable "libxml" must contain a leading underscore
Loading history...
24
25
    /**
26
     * Gets the default (preferred) configuration for libxml.
27
     */
28 1
    public static function getDefaultLibxmlConfig(): int
29
    {
30
        return \LIBXML_HTML_NOIMPLIED // Required, or things crash.
31
            | \LIBXML_BIGLINES
32
            | \LIBXML_COMPACT
33
            | \LIBXML_HTML_NODEFDTD
34
            | \LIBXML_NOBLANKS
35
            | \LIBXML_NOENT
36
            | \LIBXML_NOXMLDECL
37
            | \LIBXML_NSCLEAN
38 1
            | \LIBXML_PARSEHUGE;
39
    }
40
41
    /**
42
     * Sets the libxml value to use for parsing XML.
43
     *
44
     * @param int $libxml TODO add a description here.
45
     */
46 1
    public function setLibxml(int $libxml): self
47
    {
48 1
        $this->libxml = $libxml;
49
50
        // What are the libxml2 configurations?
51 1
        $this->logger->debug(\sprintf( // @phan-suppress-current-line PhanUndeclaredProperty
52 1
            'Libxml configuration has a bitwise value of `%s`.%s',
53 1
            (string) $this->libxml,
54 1
            (4792582 === $this->libxml)
55 1
                ? ' (This is the default configuration.)'
56 1
                : ''
57
        ));
58
59 1
        return $this;
60
    }
61
62
    /**
63
     * Gets the libxml value to use for parsing XML.
64
     */
65 1
    public function getLibxml(): int
66
    {
67 1
        return $this->libxml;
68
    }
69
}
70