Always use object in resolve relative

master
Anton Smirnov 2 years ago
parent 6ac37ac667
commit 3fdcb89162

@ -22,27 +22,9 @@ abstract class AbstractPath implements PathInterface
}
/**
* @param RelativePathInterface|string $path
* @return static
*/
public function resolveRelative($path, bool $strict = false): self
{
if (\is_string($path)) {
$path = $this->buildRelative($path);
}
return $this->doResolveRelative($path, $strict);
}
protected function buildRelative(string $path): RelativePath
{
return new RelativePath($path);
}
/**
* @return static
*/
protected function doResolveRelative(RelativePathInterface $path, bool $strict): self
public function resolveRelative(RelativePathInterface $path, bool $strict = false): self
{
if ($path instanceof RelativePath) {
// optimize

@ -11,8 +11,7 @@ interface PathInterface extends \Stringable
public function toString(): string;
/**
* @param RelativePathInterface|string $path
* @return static
*/
public function resolveRelative($path, bool $strict = false): self;
public function resolveRelative(RelativePathInterface $path, bool $strict = false): self;
}

@ -25,6 +25,11 @@ final class RelativePath extends AbstractPath implements RelativePathInterface
return new self($path, true);
}
public static function currentOS(string $path): self
{
return new self($path, DIRECTORY_SEPARATOR === '\\');
}
protected function parsePath(string $path, bool $strict): void
{
$components = explode('/', $path);
@ -49,11 +54,6 @@ final class RelativePath extends AbstractPath implements RelativePathInterface
$this->components = $parsedComponents;
}
protected function buildRelative(string $path): RelativePath
{
return new RelativePath($path, $this->windows);
}
public function isRoot(): bool
{
return $this->components[0] !== '.' && $this->components[0] !== '..';

Loading…
Cancel
Save