Completed
Push — master ( ca82a9...888d00 )
by WEBEWEB
01:51
created

StrReplaceScrapingCleaner::clean()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
rs 10
cc 3
nc 2
nop 1
1
<?php
2
3
/**
4
 * This file is part of the core-library package.
5
 *
6
 * (c) 2018 WEBEWEB
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Library\Core\Scraping\Cleaner;
13
14
/**
15
 * str_replace scraping cleaner.
16
 *
17
 * @author webeweb <https://github.com/webeweb/>
18
 * @package WBW\Library\Core\Scraping\Cleaner
19
 */
20
class StrReplaceScrapingCleaner {
21
22
    /**
23
     * Replaces.
24
     *
25
     * @var array
26
     */
27
    private $replaces;
28
29
    /**
30
     * Searches.
31
     *
32
     * @var array
33
     */
34
    private $searches;
35
36
    /**
37
     * Constructor.
38
     *
39
     * @param array $searches The searches.
40
     * @param array $replaces The replaces.
41
     */
42
    public function __construct(array $searches, array $replaces) {
43
        $this->setReplaces($replaces);
44
        $this->setSearches($searches);
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function clean($value) {
51
        if (null === $value || false === is_string($value)) {
52
            return null;
53
        }
54
        return str_replace($this->getSearches(), $this->getReplaces(), $value);
55
    }
56
57
    /**
58
     * Get the replaces.
59
     *
60
     * @return array Returns the replaces.
61
     */
62
    public function getReplaces() {
63
        return $this->replaces;
64
    }
65
66
    /**
67
     * Get the searches.
68
     *
69
     * @return array Returns the searches.
70
     */
71
    public function getSearches() {
72
        return $this->searches;
73
    }
74
75
    /**
76
     * Set the replaces.
77
     *
78
     * @param array $replaces The replaces.
79
     * @return SrapingStringReplaceCleaner Returns this str_replace cleaner.
80
     */
81
    protected function setReplaces(array $replaces) {
82
        $this->replaces = $replaces;
83
        return $this;
84
    }
85
86
    /**
87
     * Set the searches.
88
     *
89
     * @param array $searches The seaches.
90
     * @return SrapingStringReplaceCleaner Returns this str_replace cleaner.
91
     */
92
    protected function setSearches(array $searches) {
93
        $this->searches = $searches;
94
        return $this;
95
    }
96
97
}
98