Skip to content

Commit

Permalink
refactor: use constructor property promotion
Browse files Browse the repository at this point in the history
  • Loading branch information
adevade committed Jan 31, 2023
1 parent e4cc245 commit a0e1ffc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 30 deletions.
20 changes: 6 additions & 14 deletions src/UrlBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@

class UrlBuilder
{
private $domain;

private $useHttps;

private $signKey;

private $includeLibraryParam = true;
public const VERSION = '4.1.0';

public const TARGET_WIDTHS = [
Expand All @@ -34,18 +27,17 @@ class UrlBuilder

public const SRCSET_WIDTH_TOLERANCE = 0.08;

public function __construct($domain, $useHttps = true, $signKey = '', $includeLibraryParam = true)
{
public function __construct(
private $domain,
private $useHttps = true,
private $signKey = '',
private $includeLibraryParam = true,
) {
if (! is_string($domain)) {
throw new InvalidArgumentException('UrlBuilder must be passed a string domain');
}

$this->domain = $domain;
$this->validateDomain($this->domain);

$this->useHttps = $useHttps;
$this->signKey = $signKey;
$this->includeLibraryParam = $includeLibraryParam;
}

private function validateDomain($domain)
Expand Down
23 changes: 7 additions & 16 deletions src/UrlHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,14 @@

class UrlHelper
{
private $domain;

private $path;

private $scheme;

private $signKey;

private $params;

public function __construct($domain, $path, $scheme = 'http', $signKey = '', $params = [])
{
$this->domain = $domain;
public function __construct(
private $domain,
private $path,
private $scheme = 'http',
private $signKey = '',
private $params = [],
) {
$this->path = $this->formatPath($path);
$this->scheme = $scheme;
$this->signKey = $signKey;
$this->params = $params;
}

public function formatPath($path)
Expand Down

0 comments on commit a0e1ffc

Please sign in to comment.