Skip to content

Commit 386a84c

Browse files
committed
drop chevere/filesystem
1 parent 9df68ba commit 386a84c

5 files changed

Lines changed: 25 additions & 26 deletions

File tree

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121
"php": "^8.1",
2222
"ext-curl": "*",
2323
"ext-json": "*",
24-
"chevere/filesystem": "^1.0.3",
2524
"chevere/message": "^1.0.0",
25+
"chevere/parameter": "^2.0.x-dev",
2626
"chevere/standard": "^1.0.1",
2727
"chevere/throwable-handler": "^1.0.7",
2828
"chevere/trace": "^2.0.2",
29-
"chevere/var-dump": "^2.0.6",
29+
"chevere/var-dump": "^2.0.x-dev",
3030
"phpseclib/phpseclib": "~3.0"
3131
},
3232
"require-dev": {
@@ -61,7 +61,7 @@
6161
],
6262
"infection": [
6363
"Composer\\Config::disableProcessTimeout",
64-
"infection --only-covered -j10"
64+
"infection -j10"
6565
],
6666
"infection-filter": "sh -c 'sh -c \"composer infection -- --filter=$0 --test-framework-options=--filter=$0\"' $1",
6767
"phpstan": "vendor/bin/phpstan analyze src/ --memory-limit 512M --level 9",

src/Interfaces/XrInterface.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,14 @@
1313

1414
namespace Chevere\xrDebug\PHP\Interfaces;
1515

16-
use Chevere\Filesystem\Interfaces\DirectoryInterface;
17-
1816
/**
1917
* Describes the component in charge of defining XR.
2018
*/
2119
interface XrInterface
2220
{
2321
public const CONFIG_NAMES = ['isEnabled', 'isHttps', 'host', 'port', 'key'];
2422

25-
public function withConfigDir(DirectoryInterface $config): self;
23+
public function withConfigDir(string $config): self;
2624

2725
public function isEnabled(): bool;
2826

src/Xr.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,21 @@
1313

1414
namespace Chevere\xrDebug\PHP;
1515

16-
use Chevere\Filesystem\Interfaces\DirectoryInterface;
1716
use Chevere\xrDebug\PHP\Interfaces\ClientInterface;
1817
use Chevere\xrDebug\PHP\Interfaces\XrInterface;
1918
use phpseclib3\Crypt\EC\PrivateKey;
2019
use phpseclib3\Crypt\PublicKeyLoader;
2120
use Throwable;
22-
use function Chevere\Filesystem\filePhpReturnForPath;
21+
use function Chevere\Parameter\arrayp;
22+
use function Chevere\Parameter\bool;
23+
use function Chevere\Parameter\int;
24+
use function Chevere\Parameter\string;
2325

2426
final class Xr implements XrInterface
2527
{
2628
private ClientInterface $client;
2729

28-
private DirectoryInterface $directory;
30+
private string $directory;
2931

3032
private string $configFile = '';
3133

@@ -46,7 +48,7 @@ public function __construct(
4648
$this->setClient();
4749
}
4850

49-
public function withConfigDir(DirectoryInterface $config): XrInterface
51+
public function withConfigDir(string $config): XrInterface
5052
{
5153
$new = clone $this;
5254
$new->directory = $config;
@@ -99,9 +101,17 @@ public function key(): string
99101

100102
private function setConfigFromFile(): void
101103
{
104+
$arrayp = arrayp(
105+
isEnabled: bool(),
106+
isHttps: bool(),
107+
host: string(),
108+
port: int(),
109+
key: string(),
110+
)->withMakeOptional();
111+
102112
try {
103113
/** @var array<string, string|int|bool> $return */
104-
$return = filePhpReturnForPath($this->configFile)->cast()->array();
114+
$return = $arrayp(require $this->configFile);
105115
foreach (static::CONFIG_NAMES as $prop) {
106116
// @phpstan-ignore-next-line
107117
$this->{$prop} = $return[$prop] ?? $this->{$prop};
@@ -116,7 +126,7 @@ private function setConfigFromFile(): void
116126

117127
private function getConfigFile(): string
118128
{
119-
$configDirectory = $this->directory->path()->__toString();
129+
$configDirectory = $this->directory;
120130
while (is_dir($configDirectory)) {
121131
foreach ($this->configNames as $configName) {
122132
$configFullPath = $configDirectory . $configName;

src/functions.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use LogicException;
2020
use phpseclib3\Crypt\EC\PrivateKey;
2121
use Throwable;
22-
use function Chevere\Filesystem\directoryForPath;
2322
use function Chevere\Writer\streamTemp;
2423
use function getcwd;
2524

@@ -44,10 +43,7 @@ function getXr(): XrInterface
4443
if ($cwd === false) {
4544
throw new LogicException('Unable to get current working directory');
4645
}
47-
$xr = (new Xr())
48-
->withConfigDir(
49-
directoryForPath($cwd)
50-
);
46+
$xr = (new Xr())->withConfigDir($cwd);
5147

5248
return (new XrInstance($xr))::get();
5349
}

tests/XrTest.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use phpseclib3\Crypt\EC;
2020
use phpseclib3\Crypt\PublicKeyLoader;
2121
use PHPUnit\Framework\TestCase;
22-
use function Chevere\Filesystem\directoryForPath;
2322

2423
final class XrTest extends TestCase
2524
{
@@ -57,27 +56,23 @@ public function testConstructWithArguments(): void
5756
public function testConstructWithoutSettingsFileSubfolder(): void
5857
{
5958
$xr = new Xr();
60-
$with = $xr->withConfigDir(
61-
directoryForPath(__DIR__ . '/_empty/_empty/')
62-
);
59+
$with = $xr->withConfigDir(__DIR__ . '/_empty/_empty/');
6360
$this->assertNotSame($xr, $with);
6461
$this->assertSame(true, $with->isEnabled());
6562
$this->assertEquals(new Client(), $with->client());
6663
}
6764

6865
public function testConstructWithDirNotExists(): void
6966
{
70-
$xr = (new Xr())->withConfigDir(
71-
directoryForPath(__DIR__ . '/_not-found/')
72-
);
67+
$xr = (new Xr())->withConfigDir(__DIR__ . '/_not-found/');
7368
$this->assertSame(true, $xr->isEnabled());
7469
$this->assertEquals(new Client(), $xr->client());
7570
}
7671

7772
public function testConstructWithSettingsFile(): void
7873
{
79-
$configDir = directoryForPath(__DIR__ . '/src/');
80-
$return = include $configDir->path()->getChild('xr.php')->__toString();
74+
$configDir = __DIR__ . '/src/';
75+
$return = include "{$configDir}/xr.php";
8176
$xr = (new Xr())->withConfigDir($configDir);
8277
$this->assertSame($return['isEnabled'], $xr->isEnabled());
8378
$return['privateKey'] = PublicKeyLoader::load($return['key']);

0 commit comments

Comments
 (0)