Skip to content

Commit

Permalink
remove useless setters
Browse files Browse the repository at this point in the history
update tests
update xml files for updated tests
  • Loading branch information
hirohitoqwe committed Aug 9, 2024
1 parent 3b88004 commit dc9c3c3
Show file tree
Hide file tree
Showing 25 changed files with 7 additions and 153 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ vendor
.php_cs.cache
.phpunit.result.cache
.php-cs-fixer.cache
/.idea
/.phpunit.cache
17 changes: 3 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ Sitemap::create()

->add(Url::create('/home')
->setLastModificationDate(Carbon::yesterday())
->setChangeFrequency(Url::CHANGE_FREQUENCY_YEARLY)
->setPriority(0.1))


->add(...)

->writeToFile($path);
Expand All @@ -40,9 +38,7 @@ SitemapGenerator::create('https://example.com')
->getSitemap()
->add(Url::create('/extra-page')
->setLastModificationDate(Carbon::yesterday())
->setChangeFrequency(Url::CHANGE_FREQUENCY_YEARLY)
->setPriority(0.1))


->add(...)

->writeToFile($path);
Expand Down Expand Up @@ -85,8 +81,6 @@ class Post extends Model implements Sitemapable
// Return with fine-grained control:
return Url::create(route('blog.post.show', $this))
->setLastModificationDate(Carbon::create($this->updated_at))
->setChangeFrequency(Url::CHANGE_FREQUENCY_YEARLY)
->setPriority(0.1);
}
}
```
Expand Down Expand Up @@ -209,14 +203,10 @@ The generated sitemap will look similar to this:
<url>
<loc>https://example.com</loc>
<lastmod>2016-01-01T00:00:00+00:00</lastmod>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
<url>
<loc>https://example.com/page</loc>
<lastmod>2016-01-01T00:00:00+00:00</lastmod>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>

...
Expand Down Expand Up @@ -272,8 +262,7 @@ use Spatie\Sitemap\Tags\Url;
SitemapGenerator::create('https://example.com')
->hasCrawled(function (Url $url) {
if ($url->segment(1) === 'contact') {
$url->setPriority(0.9)
->setLastModificationDate(Carbon::create('2016', '1', '1'));
$url->setLastModificationDate(Carbon::create('2016', '1', '1'))
}

return $url;
Expand Down
20 changes: 0 additions & 20 deletions src/Tags/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ class Url extends Tag

public Carbon $lastModificationDate;

public string $changeFrequency;

public float $priority = 0.8;

/** @var \Spatie\Sitemap\Tags\Alternate[] */
public array $alternates = [];

Expand All @@ -43,8 +39,6 @@ public static function create(string $url): static
public function __construct(string $url)
{
$this->url = $url;

$this->changeFrequency = static::CHANGE_FREQUENCY_DAILY;
}

public function setUrl(string $url = ''): static
Expand All @@ -61,20 +55,6 @@ public function setLastModificationDate(DateTimeInterface $lastModificationDate)
return $this;
}

public function setChangeFrequency(string $changeFrequency): static
{
$this->changeFrequency = $changeFrequency;

return $this;
}

public function setPriority(float $priority): static
{
$this->priority = max(0, min($priority, 1));

return $this;
}

public function addAlternate(string $url, string $locale = ''): static
{
$this->alternates[] = new Alternate($url, $locale);
Expand Down
2 changes: 0 additions & 2 deletions tests/ImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9">
<url>
<loc>https://localhost</loc>
<changefreq>daily</changefreq>
<priority>0.8</priority>
<image:image>
<image:loc>https://localhost/favicon.ico</image:loc>
<image:caption>Favicon</image:caption>
Expand Down
2 changes: 0 additions & 2 deletions tests/NewsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9">
<url>
<loc>https://example.com</loc>
<changefreq>daily</changefreq>
<priority>0.8</priority>
<news:news>
<news:publication>
<news:name>News name</news:name>
Expand Down
2 changes: 1 addition & 1 deletion tests/SitemapGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
SitemapGenerator::create('http://localhost:4020')
->hasCrawled(function (Url $url) {
if ($url->segment(1) === 'page3') {
$url->setPriority(0.6);
$url->setLastModificationDate($this->now->subDay());
}

return $url;
Expand Down
14 changes: 0 additions & 14 deletions tests/SitemapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,6 @@
->add(
Url::create('/home')
->setLastModificationDate($this->now->subDay())
->setChangeFrequency(Url::CHANGE_FREQUENCY_YEARLY)
->setPriority(0.1)
);

assertMatchesXmlSnapshot($this->sitemap->render());
});

it('can render an url with priority 0', function () {
$this->sitemap
->add(
Url::create('/home')
->setLastModificationDate($this->now->subDay())
->setChangeFrequency(Url::CHANGE_FREQUENCY_YEARLY)
->setPriority(0.0)
);

assertMatchesXmlSnapshot($this->sitemap->render());
Expand Down
18 changes: 0 additions & 18 deletions tests/UrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,6 @@
->toEqual($carbon->toAtomString());
});

test('priority can be set')
->tap(fn () => $this->url->setPriority(0.1))
->expect(fn () => $this->url->priority)
->toEqual(0.1);

test('priority is clamped')
->tap(fn () => $this->url->setPriority(-0.1))
->expect(fn () => $this->url->priority)
->toEqual(0)
->tap(fn () => $this->url->setPriority(1.1))
->expect(fn () => $this->url->priority)
->toEqual(1);

test('change frequency can be set')
->tap(fn () => $this->url->setChangeFrequency(Url::CHANGE_FREQUENCY_YEARLY))
->expect(fn () => $this->url->changeFrequency)
->toEqual(Url::CHANGE_FREQUENCY_YEARLY);

test('alternate can be added', function () {
$url = 'defaultUrl';
$locale = 'en';
Expand Down
2 changes: 0 additions & 2 deletions tests/VideoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9">
<url>
<loc>https://example.com</loc>
<changefreq>daily</changefreq>
<priority>0.8</priority>
<video:video>
<video:thumbnail_loc>https://example.com/image.jpg</video:thumbnail_loc>
<video:title>My Test Title</video:title>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,20 @@
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9">
<url>
<loc>http://localhost:4020/</loc>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
<url>
<loc>http://localhost:4020/page1</loc>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
<url>
<loc>http://localhost:4020/page2</loc>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
<url>
<loc>http://localhost:4020/page3</loc>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
<url>
<loc>http://localhost:4020/page4</loc>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
<url>
<loc>http://localhost:4020/page5</loc>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
</urlset>
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,21 @@
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9">
<url>
<loc>http://localhost:4020/</loc>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
<url>
<loc>http://localhost:4020/page1</loc>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
<url>
<loc>http://localhost:4020/page2</loc>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
<url>
<loc>http://localhost:4020/page3</loc>
<changefreq>daily</changefreq>
<priority>0.6</priority>
<lastmod>2015-12-31T00:00:00+00:00</lastmod>
</url>
<url>
<loc>http://localhost:4020/page4</loc>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
<url>
<loc>http://localhost:4020/page5</loc>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
</urlset>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9">
<url>
<loc>http://localhost:4020/</loc>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
</urlset>
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,17 @@
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9">
<url>
<loc>http://localhost:4020/</loc>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
<url>
<loc>http://localhost:4020/page1</loc>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
<url>
<loc>http://localhost:4020/page2</loc>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
<url>
<loc>http://localhost:4020/page4</loc>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
<url>
<loc>http://localhost:4020/page5</loc>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
</urlset>
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,14 @@
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9">
<url>
<loc>http://localhost:4020/</loc>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
<url>
<loc>http://localhost:4020/page1</loc>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
<url>
<loc>http://localhost:4020/page2</loc>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
<url>
<loc>http://localhost:4020/page4</loc>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
</urlset>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9">
<url>
<loc>http://localhost/home</loc>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
</urlset>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9">
<url>
<loc>http://localhost/home</loc>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
</urlset>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9">
<url>
<loc>http://localhost/home</loc>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
</urlset>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9">
<url>
<loc>http://localhost/home</loc>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
</urlset>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@
<loc>http://localhost/home</loc>
<xhtml:link rel="alternate" hreflang="nl" href="http://localhost/thuis"/>
<xhtml:link rel="alternate" hreflang="fr" href="http://localhost/maison"/>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
</urlset>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,5 @@
<url>
<loc>http://localhost/home</loc>
<lastmod>2015-12-31T00:00:00+00:00</lastmod>
<changefreq>yearly</changefreq>
<priority>0.1</priority>
</url>
</urlset>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,5 @@
<url>
<loc>http://localhost/home</loc>
<lastmod>2015-12-31T00:00:00+00:00</lastmod>
<changefreq>yearly</changefreq>
<priority>0.0</priority>
</url>
</urlset>
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9">
<url>
<loc>http://localhost</loc>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
<url>
<loc>http://localhost/home</loc>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
</urlset>
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9">
<url>
<loc>http://localhost/home</loc>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
<url>
<loc>http://localhost/contact</loc>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
</urlset>
Loading

0 comments on commit dc9c3c3

Please sign in to comment.