Skip to content

Commit

Permalink
🎨 Add missing types
Browse files Browse the repository at this point in the history
  • Loading branch information
Log1x committed Dec 21, 2023
1 parent 58c827e commit f07d89a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 56 deletions.
4 changes: 1 addition & 3 deletions src/Contracts/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ interface Module
{
/**
* Handle the module.
*
* @return array
*/
public function handle();
public function handle(): void;
}
26 changes: 6 additions & 20 deletions src/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,20 @@ class Document
{
/**
* The DOMDocument instance.
*
* @var DOMDocument
*/
protected $document;
protected DOMDocument $document;

/**
* The XML encoding tag.
*
* @var string
*/
protected $encoding = '<?xml encoding="UTF-8">';
protected string $encoding = '<?xml encoding="UTF-8">';

/**
* Create a new DOM instance.
*
* @param string $html
* @return void
*/
public function __construct($html)
public function __construct(string $html)
{
$this->document = new DOMDocument();

Expand All @@ -46,10 +41,8 @@ public function __construct($html)

/**
* Make a new DOM instance.
*
* @param string $html
*/
public static function make($html): self
public static function make(string $html): self
{
return new static($html);
}
Expand Down Expand Up @@ -86,23 +79,16 @@ public function html(): string

/**
* Call methods on the root document.
*
* @param string $name
* @param array $arguments
* @return mixed
*/
public function __call($name, $arguments)
public function __call(string $name, array $arguments): mixed
{
return $this->document->{$name}(...$arguments);
}

/**
* Get properties from the root document.
*
* @param string $name
* @return mixed
*/
public function __get($name)
public function __get(string $name): mixed
{
return $this->document->{$name};
}
Expand Down
22 changes: 5 additions & 17 deletions src/Modules/CleanUpModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
namespace Roots\AcornPretty\Modules;

use Illuminate\Support\Str;
use Roots\AcornPretty\Contracts\Module;
use Roots\AcornPretty\Document;

class CleanUpModule extends AbstractModule implements Module
class CleanUpModule extends AbstractModule
{
/**
* The module key.
Expand Down Expand Up @@ -147,10 +146,8 @@ protected function handleDisableExtraRss(): self

/**
* Disable recent comments CSS.
*
* @return self
*/
protected function handleDisableRecentCommentsCss()
protected function handleDisableRecentCommentsCss(): self
{
if (! $this->config->get('disable-recent-comments-css')) {
return $this;
Expand Down Expand Up @@ -205,12 +202,8 @@ public function cleanScriptTags(string $html): string

/**
* Add and remove body_class() classes.
*
* @param array $classes
* @param array $disallowedClasses
* @return array
*/
public function bodyClass($classes, $disallowedClasses = ['page-template-default'])
public function bodyClass(array $classes, array $disallowedClasses = ['page-template-default']): array
{
if (is_single() || is_page() && ! is_front_page()) {
if (! in_array($slug = basename(get_permalink()), $classes, true)) {
Expand All @@ -230,10 +223,8 @@ public function bodyClass($classes, $disallowedClasses = ['page-template-default

/**
* Clean up language_attributes() used in <html> tag.
*
* @return string
*/
public function languageAttributes()
public function languageAttributes(): string
{
$attributes = [];

Expand All @@ -252,11 +243,8 @@ public function languageAttributes()

/**
* Remove self-closing tags.
*
* @param string|string[] $html
* @return string|string[]
*/
public function removeSelfClosingTags($html)
public function removeSelfClosingTags(string|array $html): string|array
{
return str_replace(' />', '>', $html);
}
Expand Down
4 changes: 1 addition & 3 deletions src/Modules/NiceSearchModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

namespace Roots\AcornPretty\Modules;

use Roots\AcornPretty\Contracts\Module;

class NiceSearchModule extends AbstractModule implements Module
class NiceSearchModule extends AbstractModule
{
/**
* The module key.
Expand Down
17 changes: 4 additions & 13 deletions src/Modules/RelativeUrlsModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
namespace Roots\AcornPretty\Modules;

use Illuminate\Support\Str;
use Roots\AcornPretty\Contracts\Module;

class RelativeUrlsModule extends AbstractModule implements Module
class RelativeUrlsModule extends AbstractModule
{
/**
* The module key.
Expand Down Expand Up @@ -40,11 +39,8 @@ public function handle(): void

/**
* Convert an absolute URL to a relative URL.
*
* @param string $url
* @return string
*/
public function relativeUrl($url)
public function relativeUrl(string $url): string
{
if (is_feed()) {
return $url;
Expand All @@ -63,7 +59,7 @@ public function relativeUrl($url)
* @param string[] $sources
* @return string[]
*/
public function imageSrcset($sources)
public function imageSrcset(string|array $sources): string|array
{
if (! is_array($sources)) {
return $sources;
Expand Down Expand Up @@ -107,13 +103,8 @@ protected function handleSeoFramework(): self

/**
* Determine if two URLs contain the same base URL.
*
* @param string $baseUrl
* @param string $inputUrl
* @param bool $strict
* @return bool
*/
protected function compareBaseUrl($baseUrl, $inputUrl, $strict = true)
protected function compareBaseUrl(string $baseUrl, string $inputUrl, bool $strict = true): bool
{
$baseUrl = trailingslashit($baseUrl);
$inputUrl = trailingslashit($inputUrl);
Expand Down

0 comments on commit f07d89a

Please sign in to comment.