Completed
Push — master ( ce7b38...6ec792 )
by Peter
04:34
created

PlainTextKeeper::save()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 11
ccs 0
cts 9
cp 0
rs 9.4285
cc 1
eloc 7
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * GpsLab component.
4
 *
5
 * @author    Peter Gribanov <[email protected]>
6
 * @copyright Copyright (c) 2011, Peter Gribanov
7
 * @license   http://opensource.org/licenses/MIT
8
 */
9
namespace GpsLab\Component\Sitemap\Uri\Keeper;
10
11
use GpsLab\Component\Sitemap\Uri\UriInterface;
12
13
class PlainTextKeeper implements KeeperInterface
14
{
15
    /**
16
     * @var string
17
     */
18
    protected $filename = '';
19
20
    /**
21
     * @var string
22
     */
23
    protected $content = '';
24
25
    /**
26
     * @param string $filename
27
     */
28
    public function __construct($filename)
29
    {
30
        $this->filename = $filename;
31
    }
32
33
    /**
34
     * @param UriInterface $url
35
     *
36
     * @return self
37
     */
38 View Code Duplication
    public function addUri(UriInterface $url)
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
39
    {
40
        $this->content .= '<url>'.
41
                '<loc>'.htmlspecialchars($url->getLoc()).'</loc>'.
42
                '<lastmod>'.$url->getLastMod()->format('Y-m-d').'</lastmod>'.
43
                '<changefreq>'.$url->getChangeFreq().'</changefreq>'.
44
                '<priority>'.$url->getPriority().'</priority>'.
45
            '</url>';
46
47
        return $this;
48
    }
49
50
    /**
51
     * @return bool
52
     */
53
    public function save()
54
    {
55
        $content = '<?xml version="1.0" encoding="utf-8"?>'.
56
            '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'.
57
            $this->content.
58
            '</urlset>';
59
60
        $this->content = '';
61
62
        return (bool)file_put_contents($this->filename, $content);
63
    }
64
}
65