Whitespace::concatenateDoubleOrMoreSpaces()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * Copyright (c) 2016 Martin Dilling-Hansen <[email protected]>
4
 * https://github.com/scripturadesign/tokenizer
5
 */
6
7
namespace Scriptura\Tokenizer\Tokenizers;
8
9
use Scriptura\Tokenizer\Tokenizer;
10
11
class Whitespace implements Tokenizer
12
{
13
    /**
14
     * Get the token sequence from a character sequence
15
     *
16
     * @param string $string
17
     *
18
     * @return array
19
     */
20 3
    public function tokenize($string)
21
    {
22 3
        $string = $this->concatenateDoubleOrMoreSpaces($string);
23 3
        $string = $this->removeStartingAndEndingSpaces($string);
24
25 3
        return explode(' ', $string);
26
    }
27
28 3
    protected function concatenateDoubleOrMoreSpaces($string)
29
    {
30 3
        return preg_replace('/  +/', ' ', $string);
31
    }
32
33 3
    protected function removeStartingAndEndingSpaces($string)
34
    {
35 3
        return trim($string);
36
    }
37
}
38