Completed
Push — master ( 18c02e...701e2d )
by Sébastien
05:57
created

ParserFactory::parse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * soluble-japha / PHPJavaBridge driver client.
4
 *
5
 * Refactored version of phpjababridge's Java.inc file compatible
6
 * with php java bridge 6.2
7
 *
8
 *
9
 * @credits   http://php-java-bridge.sourceforge.net/pjb/
10
 *
11
 * @see      http://github.com/belgattitude/soluble-japha
12
 *
13
 * @author Jost Boekemeier
14
 * @author Vanvelthem Sébastien (refactoring and fixes from original implementation)
15
 * @license   MIT
16
 *
17
 * The MIT License (MIT)
18
 * Copyright (c) 2014-2017 Jost Boekemeier
19
 * Permission is hereby granted, free of charge, to any person obtaining a copy
20
 * of this software and associated documentation files (the "Software"), to deal
21
 * in the Software without restriction, including without limitation the rights
22
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
23
 * copies of the Software, and to permit persons to whom the Software is
24
 * furnished to do so, subject to the following conditions:
25
 *
26
 * The above copyright notice and this permission notice shall be included in
27
 * all copies or substantial portions of the Software.
28
 *
29
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
35
 * THE SOFTWARE.
36
 */
37
38
namespace Soluble\Japha\Bridge\Driver\Pjb62;
39
40
class ParserFactory
41
{
42
    public const PARSER_NATIVE = 'NATIVE';
43
    public const PARSER_SIMPLE = 'SIMPLE';
44
45
    /**
46
     * @var ParserInterface
47
     */
48
    protected $parser;
49
50
    /**
51
     * @param Client $handler
52
     * @param bool   $forceSimpleParser - Always use SimpleParser, even if NativeParser can be used
53
     */
54 26
    public function __construct(Client $handler, bool $forceSimpleParser = false)
55
    {
56 26
        if ($forceSimpleParser || defined('HHVM_VERSION') || !function_exists('xml_parser_create')) {
57
            // Later on maybe a version_compare(HHVM_VERSION, '3.8.0', '<')
58
            // xml_parser bugs in hhvm at least version 3.7.0
59 2
            $this->parser = new SimpleParser($handler);
60 2
            $handler->RUNTIME['PARSER'] = self::PARSER_SIMPLE;
61
        } else {
62 26
            $this->parser = new NativeParser($handler);
63 26
            $handler->RUNTIME['PARSER'] = self::PARSER_NATIVE;
64
        }
65 26
    }
66
67 113
    public function parse(): void
68
    {
69 113
        $this->parser->parse();
70 112
    }
71
72
    /**
73
     * @param string $str
74
     *
75
     * @return string
76
     */
77 88
    public function getData(string $str): string
78
    {
79 88
        return $this->parser->getData($str);
80
    }
81
}
82