Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
taoItems_models_classes_search_XmlItemContentTokenizer
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
6
100.00% covered (success)
100.00%
1 / 1
 getStrings
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
6
1<?php
2
3/**
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; under version 2
7 * of the License (non-upgradable).
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 *
18 * Copyright (c) 2014 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
19 *
20 */
21
22use oat\tao\model\search\tokenizer\Tokenizer;
23
24/**
25 * XML Based Item Tokenizer.
26 *
27 * This Tokenizer implementation retrieves all text nodes of given
28 * XML files as the final list of tokens.
29 *
30 * @author Jérôme Bogaerts <jerome@taotesting.com>
31 */
32class taoItems_models_classes_search_XmlItemContentTokenizer implements Tokenizer
33{
34    public function getStrings($values)
35    {
36        $contentStrings = [];
37
38        if (is_array($values) === false) {
39            $values = [$values];
40        }
41
42        foreach ($values as $value) {
43            if ($value instanceof DOMDocument) {
44                $xpath = new DOMXPath($value);
45                $textNodes = $xpath->query('//text()');
46                unset($xpath);
47
48                foreach ($textNodes as $textNode) {
49                    if (ctype_space($textNode->wholeText) === false) {
50                        $contentStrings[] = trim($textNode->wholeText);
51                    }
52                }
53            }
54        }
55
56        return $contentStrings;
57    }
58}