Skip to content

Commit

Permalink
Merge pull request #3 from vinogradsoft/1.1.0-dev
Browse files Browse the repository at this point in the history
Added getLast method to the Compass\Path class.
  • Loading branch information
vinogradsoft committed Oct 20, 2023
2 parents 939a8f1 + 060844a commit 68fa27f
Show file tree
Hide file tree
Showing 21 changed files with 63 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ echo '<br>', $path; # newPath/newTo/file.v
$path->replace('newPath','path');
$path->updateSource();
echo '<br>', $path; # path/newTo/file.v
echo '<br>', $path->getLast(); # file.v
```

## Тестировать
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"email": "[email protected]"
}
],
"version": "1.0.0",
"version": "1.1.0",
"minimum-stability": "stable",
"autoload": {
"psr-4": {
Expand Down
1 change: 1 addition & 0 deletions src/AbstractPath.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace Compass;

Expand Down
1 change: 1 addition & 0 deletions src/DefaultPathStrategy.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace Compass;

Expand Down
1 change: 1 addition & 0 deletions src/DefaultQueryStrategy.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace Compass;

Expand Down
1 change: 1 addition & 0 deletions src/DefaultUrlStrategy.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace Compass;

Expand Down
3 changes: 2 additions & 1 deletion src/Exception/InvalidPathException.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php
declare(strict_types=1);

namespace Compass\Exception;

class InvalidPathException extends \DomainException
class InvalidPathException extends \DomainException
{

}
3 changes: 2 additions & 1 deletion src/Exception/InvalidUrlException.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php
declare(strict_types=1);

namespace Compass\Exception;

class InvalidUrlException extends \DomainException
class InvalidUrlException extends \DomainException
{

}
17 changes: 17 additions & 0 deletions src/Path.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace Compass;

Expand Down Expand Up @@ -64,6 +65,22 @@ public static function createBlank(string $separator = DIRECTORY_SEPARATOR, ?Pat
return (clone $prototypePath)->initUrlPath($separator, $strategy);
}

/**
* @param bool $withSuffix
* @return string|null
*/
public function getLast(bool $withSuffix = true): ?string
{
$lastItem = $this->items[count($this->items) - 1] ?? null;
if ($lastItem === null) {
return null;
}
if ($withSuffix && !empty($this->suffix)) {
return $lastItem . $this->suffix;
}
return $lastItem;
}

/**
* @param PathStrategy $strategy
*/
Expand Down
1 change: 1 addition & 0 deletions src/PathStrategy.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace Compass;

Expand Down
1 change: 1 addition & 0 deletions src/Query.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace Compass;

Expand Down
1 change: 1 addition & 0 deletions src/QueryStrategy.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace Compass;

Expand Down
3 changes: 2 additions & 1 deletion src/Url.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace Compass;

Expand Down Expand Up @@ -299,7 +300,7 @@ public function setHost(string $host): static
*/
public function getPort(): ?string
{
return !empty($this->items[self::PORT]) ? $this->items[self::PORT] : null;
return !empty($this->items[self::PORT]) ? (string)$this->items[self::PORT] : null;
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/UrlStrategy.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace Compass;

Expand Down
1 change: 1 addition & 0 deletions tests/DefaultPathStrategyTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace Test;

Expand Down
1 change: 1 addition & 0 deletions tests/DefaultUrlQueryStrategyTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace Test;

Expand Down
1 change: 1 addition & 0 deletions tests/DefaultUrlStrategyTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace Test;

Expand Down
23 changes: 23 additions & 0 deletions tests/PathTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace Test;

Expand Down Expand Up @@ -34,6 +35,28 @@ public function testGetAssertionNegative()
$path->get(-1);
}

/**
* @dataProvider getCasesGet
*/
public function testGetLast($source, $withSuffix, $expect)
{
$path = new Path($source);
self::assertEquals($expect, $path->getLast($withSuffix));
}

/**
* @return array
*/
public function getCasesGet(): array
{
return [
'standard' => ['/src/Scanner/Driver/File/index.php', true, 'index.php'],
'dot' => ['/src/Scanner/Driver/File/.php', true, '.php'],
'no dot' => ['/src/Scanner/Driver/File/name', true, 'name'],
'empty' => ['/', true, null],
];
}

public function testReplaceAll()
{
$path = new Path('/s__NAME____NAME__rc/__NAME__Scanner/Driver__NAME__/Fi__NAME2__le/');
Expand Down
1 change: 1 addition & 0 deletions tests/UrlPathTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace Test;

Expand Down
1 change: 1 addition & 0 deletions tests/UrlQueryTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace Test;

Expand Down
3 changes: 2 additions & 1 deletion tests/UrlTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);

namespace Test;

Expand Down Expand Up @@ -248,7 +249,7 @@ public function testRepeatReset()

$url->reset();
$url->setSource('http://vinograd.ru');
$url->setPort(80);
$url->setPort('80');
$url->updateSource();
self::assertEquals('http://vinograd.ru:80', $url->getSource());
}
Expand Down

0 comments on commit 68fa27f

Please sign in to comment.