Skip to content

Commit

Permalink
Use php8 str_starts_with
Browse files Browse the repository at this point in the history
  • Loading branch information
sreichel authored and cmuench committed Jul 13, 2024
1 parent 8c78dd4 commit bfe0818
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 35 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"symfony/console": "~5.4",
"symfony/event-dispatcher": "~5.4",
"symfony/finder": "~5.4",
"symfony/polyfill-php80": "^1.30",
"symfony/process": "~5.4",
"symfony/validator": "~5.4",
"symfony/yaml": "~5.4",
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function execute()
$dbOptionsFound = 0;
foreach ($dbOptions as $dbOption) {
foreach ($this->getCliArguments() as $definedCliOption) {
if (BinaryString::startsWith($definedCliOption, $dbOption)) {
if (str_starts_with($definedCliOption, $dbOption)) {
$dbOptionsFound++;
}
}
Expand Down
11 changes: 0 additions & 11 deletions src/N98/Util/BinaryString.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,4 @@ public static function startsWith($haystack, $needle)
{
return $needle === '' || strpos($haystack, $needle) === 0;
}

/**
* @param string $haystack
* @param string $needle
*
* @return bool
*/
public static function endsWith($haystack, $needle)
{
return $needle === '' || substr($haystack, -strlen($needle)) === $needle;
}
}
3 changes: 1 addition & 2 deletions src/N98/Util/Console/Helper/ComposerHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace N98\Util\Console\Helper;

use N98\Util\BinaryString;
use N98\Util\OperatingSystem;
use Symfony\Component\Console\Helper\Helper as AbstractHelper;
use Symfony\Component\Console\Input\InputAwareInterface;
Expand Down Expand Up @@ -72,7 +71,7 @@ public function getConfigValue($key, $useGlobalConfig = true)
$lines = explode(PHP_EOL, $composerOutput);

foreach ($lines as $line) {
if (BinaryString::startsWith($line, 'Changed current directory to')) {
if (str_starts_with($line, 'Changed current directory to')) {
continue;
}

Expand Down
20 changes: 0 additions & 20 deletions tests/N98/Util/BinaryStringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,4 @@ public function trimExplodeEmptyProvider()
{
return [[',', 'Foo,Bar', ['Foo', 'Bar']], ['#', ' Foo# Bar', ['Foo', 'Bar']], [',', ',,Foo, Bar,,', ['Foo', 'Bar']]];
}

/**
* @test
*/
public function startsWith()
{
self::assertTrue(BinaryString::startsWith('Foo', 'Foo'));
self::assertTrue(BinaryString::startsWith('Foo123', 'Foo'));
self::assertFalse(BinaryString::startsWith(' Foo123', 'Foo'));
}

/**
* @test
*/
public function endsWith()
{
self::assertTrue(BinaryString::endsWith('Foo', 'Foo'));
self::assertTrue(BinaryString::endsWith('Foo123', '123'));
self::assertFalse(BinaryString::endsWith(' Foo123 ', '123'));
}
}

0 comments on commit bfe0818

Please sign in to comment.