Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
100.00% |
1 / 1 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
13 / 13 |
| PathProcessor | |
100.00% |
1 / 1 |
|
100.00% |
3 / 3 |
4 | |
100.00% |
13 / 13 |
| process(array $items) | |
100.00% |
1 / 1 |
2 | |
100.00% |
4 / 4 |
|||
| fixPaths(Item $item) | |
100.00% |
1 / 1 |
1 | |
100.00% |
4 / 4 |
|||
| getFixedText($text, $domain) | |
100.00% |
1 / 1 |
1 | |
100.00% |
5 / 5 |
|||
| <?php | |
| /** | |
| * This file is part of the planetubuntu package. | |
| * | |
| * (c) Daniel González <daniel@desarrolla2.com> | |
| * | |
| * For the full copyright and license information, please view the LICENSE | |
| * file that was distributed with this source code. | |
| */ | |
| namespace FastFeed\Processor; | |
| use FastFeed\Item; | |
| use FastFeed\Url\Url; | |
| /** | |
| * PathProcessor | |
| */ | |
| class PathProcessor implements ProcessorInterface | |
| { | |
| /** | |
| * Execute processor | |
| * | |
| * @param array $items | |
| * | |
| * @return array $items | |
| */ | |
| public function process(array $items) | |
| { | |
| foreach ($items as $key => $item) { | |
| $items[$key] = $this->fixPaths($item); | |
| } | |
| return $items; | |
| } | |
| /** | |
| * @param Item $item | |
| * | |
| * @return Item | |
| */ | |
| protected function fixPaths(Item $item) | |
| { | |
| $url = new Url($item->getSource()); | |
| $item->setIntro($this->getFixedText($item->getIntro(), $url->getFullHost())); | |
| $item->setContent($this->getFixedText($item->getContent(), $url->getFullHost())); | |
| return $item; | |
| } | |
| /** | |
| * @param $text | |
| * @param $domain | |
| * | |
| * @return mixed | |
| */ | |
| protected function getFixedText($text, $domain) | |
| { | |
| $text = str_ireplace('href="/', 'href="' . $domain . '/', $text); | |
| $text = str_ireplace('href=\'/', 'href=\'' . $domain . '/', $text); | |
| $text = str_ireplace('src="/', 'src="' . $domain . '/', $text); | |
| $text = str_ireplace('src=\'/', 'src=\'' . $domain . '/', $text); | |
| return $text; | |
| } | |
| } |