Skip to content

Commit

Permalink
all these fixes are a result of phpcbf
Browse files Browse the repository at this point in the history
  • Loading branch information
dpi committed Mar 8, 2021
1 parent 32aed29 commit 9c2667d
Show file tree
Hide file tree
Showing 14 changed files with 138 additions and 148 deletions.
8 changes: 0 additions & 8 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,4 @@
<rule ref="SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming.SuperfluousPrefix">
<exclude-pattern>src/Purl/AbstractPart.php</exclude-pattern>
</rule>

<rule ref="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint">
<exclude-pattern>src/Purl/AbstractPart.php</exclude-pattern>
</rule>

<rule ref="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint">
<exclude-pattern>src/Purl/AbstractPart.php</exclude-pattern>
</rule>
</ruleset>
43 changes: 19 additions & 24 deletions src/Purl/AbstractPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,18 @@
*/
abstract class AbstractPart implements ArrayAccess
{
/** @var bool */
protected $initialized = false;
protected bool $initialized = false;

/** @var mixed[] */
protected $data = [];
protected array $data = [];

/** @var string[] */
protected $partClassMap = [];
protected array $partClassMap = [];

/**
* @return mixed[]
*/
public function getData() : array
public function getData(): array
{
$this->initialize();

Expand All @@ -35,19 +34,19 @@ public function getData() : array
/**
* @param mixed[] $data
*/
public function setData(array $data) : void
public function setData(array $data): void
{
$this->initialize();

$this->data = $data;
}

public function isInitialized() : bool
public function isInitialized(): bool
{
return $this->initialized;
}

public function has(string $key) : bool
public function has(string $key): bool
{
$this->initialize();

Expand All @@ -67,7 +66,7 @@ public function get(string $key)
/**
* @param mixed $value
*/
public function set(string $key, $value) : AbstractPart
public function set(string $key, $value): AbstractPart
{
$this->initialize();
$this->data[$key] = $value;
Expand All @@ -78,15 +77,15 @@ public function set(string $key, $value) : AbstractPart
/**
* @param mixed $value
*/
public function add($value) : AbstractPart
public function add($value): AbstractPart
{
$this->initialize();
$this->data[] = $value;

return $this;
}

public function remove(string $key) : AbstractPart
public function remove(string $key): AbstractPart
{
$this->initialize();

Expand All @@ -95,7 +94,7 @@ public function remove(string $key) : AbstractPart
return $this;
}

public function __isset(string $key) : bool
public function __isset(string $key): bool
{
return $this->has($key);
}
Expand All @@ -111,20 +110,20 @@ public function __get(string $key)
/**
* @param mixed $value
*/
public function __set(string $key, $value) : AbstractPart
public function __set(string $key, $value): AbstractPart
{
return $this->set($key, $value);
}

public function __unset(string $key) : void
public function __unset(string $key): void
{
$this->remove($key);
}

/**
* @param mixed $key
*/
public function offsetExists($key) : bool
public function offsetExists($key): bool
{
$this->initialize();

Expand All @@ -144,25 +143,21 @@ public function offsetGet($key)
/**
* @param mixed $key
* @param mixed $value
*
* @return void
*/
public function offsetSet($key, $value)
public function offsetSet($key, $value): void
{
$this->set($key, $value);
}

/**
* @param mixed $key
*
* @return void
*/
public function offsetUnset($key)
public function offsetUnset($key): void
{
$this->remove($key);
}

protected function initialize() : void
protected function initialize(): void
{
if ($this->initialized === true) {
return;
Expand All @@ -189,7 +184,7 @@ protected function preparePartValue(string $key, $value)
return ! $value instanceof $className ? new $className($value) : $value;
}

abstract public function __toString() : string;
abstract public function __toString(): string;

abstract protected function doInitialize() : void;
abstract protected function doInitialize(): void;
}
24 changes: 12 additions & 12 deletions src/Purl/Fragment.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
class Fragment extends AbstractPart
{
/** @var string|null The original fragment string. */
private $fragment;
private ?string $fragment = null;

/** @var mixed[] */
protected $data = [
protected array $data = [
'path' => null,
'query' => null,
];

/** @var string[] */
protected $partClassMap = [
protected array $partClassMap = [
'path' => 'Purl\Path',
'query' => 'Purl\Query',
];
Expand All @@ -50,15 +50,15 @@ public function __construct($fragment = null, ?Query $query = null)
/**
* @param mixed $value
*/
public function set(string $key, $value) : AbstractPart
public function set(string $key, $value): AbstractPart
{
$this->initialize();
$this->data[$key] = $this->preparePartValue($key, $value);

return $this;
}

public function getFragment() : string
public function getFragment(): string
{
$this->initialize();

Expand All @@ -69,7 +69,7 @@ public function getFragment() : string
);
}

public function setFragment(string $fragment) : AbstractPart
public function setFragment(string $fragment): AbstractPart
{
$this->initialized = false;
$this->data = [];
Expand All @@ -78,40 +78,40 @@ public function setFragment(string $fragment) : AbstractPart
return $this;
}

public function setPath(Path $path) : AbstractPart
public function setPath(Path $path): AbstractPart
{
$this->data['path'] = $path;

return $this;
}

public function getPath() : Path
public function getPath(): Path
{
$this->initialize();

return $this->data['path'];
}

public function setQuery(Query $query) : AbstractPart
public function setQuery(Query $query): AbstractPart
{
$this->data['query'] = $query;

return $this;
}

public function getQuery() : Query
public function getQuery(): Query
{
$this->initialize();

return $this->data['query'];
}

public function __toString() : string
public function __toString(): string
{
return $this->getFragment();
}

protected function doInitialize() : void
protected function doInitialize(): void
{
if ($this->fragment !== null) {
$parsed = parse_url($this->fragment);
Expand Down
7 changes: 4 additions & 3 deletions src/Purl/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Purl;

use InvalidArgumentException;

use function array_merge;
use function array_reverse;
use function explode;
Expand All @@ -18,7 +19,7 @@
class Parser implements ParserInterface
{
/** @var mixed[] */
private static $defaultParts = [
private static array $defaultParts = [
'scheme' => null,
'host' => null,
'port' => null,
Expand All @@ -36,7 +37,7 @@ class Parser implements ParserInterface
*
* @return mixed[]
*/
public function parseUrl($url) : array
public function parseUrl($url): array
{
$url = (string) $url;

Expand Down Expand Up @@ -64,7 +65,7 @@ public function parseUrl($url) : array
/**
* @return mixed[]
*/
protected function doParseUrl(string $url) : array
protected function doParseUrl(string $url): array
{
$parsedUrl = parse_url($url);

Expand Down
2 changes: 1 addition & 1 deletion src/Purl/ParserInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ interface ParserInterface
*
* @return mixed[]
*/
public function parseUrl($url) : array;
public function parseUrl($url): array;
}
12 changes: 6 additions & 6 deletions src/Purl/Path.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
class Path extends AbstractPart
{
/** @var string|null The original path string. */
private $path;
private ?string $path = null;

public function __construct(?string $path = null)
{
$this->path = $path;
}

public function getPath() : string
public function getPath(): string
{
$this->initialize();

Expand All @@ -31,7 +31,7 @@ public function getPath() : string
}, $this->data));
}

public function setPath(string $path) : void
public function setPath(string $path): void
{
$this->initialized = false;
$this->path = $path;
Expand All @@ -40,19 +40,19 @@ public function setPath(string $path) : void
/**
* @return mixed[]
*/
public function getSegments() : array
public function getSegments(): array
{
$this->initialize();

return $this->data;
}

public function __toString() : string
public function __toString(): string
{
return $this->getPath();
}

protected function doInitialize() : void
protected function doInitialize(): void
{
$this->data = explode('/', (string) $this->path);
}
Expand Down
10 changes: 5 additions & 5 deletions src/Purl/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,32 @@
class Query extends AbstractPart
{
/** @var string|null The original query string. */
private $query;
private ?string $query = null;

public function __construct(?string $query = null)
{
$this->query = $query;
}

public function getQuery() : string
public function getQuery(): string
{
$this->initialize();

return http_build_query($this->data);
}

public function setQuery(string $query) : void
public function setQuery(string $query): void
{
$this->initialized = false;
$this->query = $query;
}

public function __toString() : string
public function __toString(): string
{
return $this->getQuery();
}

protected function doInitialize() : void
protected function doInitialize(): void
{
parse_str((string) $this->query, $data);

Expand Down
Loading

0 comments on commit 9c2667d

Please sign in to comment.