Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- `Innmind\Server\Status\Server::cpu()` now returns `Innmind\Immutable\Attempt<Innmind\Server\Status\Server\Cpu>`
- `Innmind\Server\Status\Server::memory()` now returns `Innmind\Immutable\Attempt<Innmind\Server\Status\Server\Memory>`
- `Innmind\Server\Status\Server::loadAverage()` now returns `Innmind\Immutable\Attempt<Innmind\Server\Status\Server\LoadAverage>`
- `Innmind\Server\Status\Server\Logger` constructor is now private, use `::of()` instead

### Removed

Expand Down
7 changes: 6 additions & 1 deletion src/Server/Disk/LoggerDisk.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@ final class LoggerDisk implements Disk
private Disk $disk;
private LoggerInterface $logger;

public function __construct(Disk $disk, LoggerInterface $logger)
private function __construct(Disk $disk, LoggerInterface $logger)
{
$this->disk = $disk;
$this->logger = $logger;
}

public static function of(Disk $disk, LoggerInterface $logger): self
{
return new self($disk, $logger);
}

#[\Override]
public function volumes(): Set
{
Expand Down
7 changes: 6 additions & 1 deletion src/Server/Disk/UnixDisk.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,16 @@ final class UnixDisk implements Disk

private Processes $processes;

public function __construct(Processes $processes)
private function __construct(Processes $processes)
{
$this->processes = $processes;
}

public static function of(Processes $processes): self
{
return new self($processes);
}

#[\Override]
public function volumes(): Set
{
Expand Down
7 changes: 6 additions & 1 deletion src/Server/Processes/LoggerProcesses.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@ final class LoggerProcesses implements Processes
private Processes $processes;
private LoggerInterface $logger;

public function __construct(Processes $processes, LoggerInterface $logger)
private function __construct(Processes $processes, LoggerInterface $logger)
{
$this->processes = $processes;
$this->logger = $logger;
}

public static function of(Processes $processes, LoggerInterface $logger): self
{
return new self($processes, $logger);
}

#[\Override]
public function all(): Set
{
Expand Down
7 changes: 6 additions & 1 deletion src/Server/Processes/UnixProcesses.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,17 @@ final class UnixProcesses implements Processes
private Clock $clock;
private Control\Processes $processes;

public function __construct(Clock $clock, Control\Processes $processes)
private function __construct(Clock $clock, Control\Processes $processes)
{
$this->clock = $clock;
$this->processes = $processes;
}

public static function of(Clock $clock, Control\Processes $processes): self
{
return new self($clock, $processes);
}

#[\Override]
public function all(): Set
{
Expand Down
4 changes: 2 additions & 2 deletions src/ServerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public static function build(
EnvironmentPath $path,
): Server {
return match (\PHP_OS) {
'Darwin' => new OSX($clock, $control, $path),
'Linux' => new Linux($clock, $control),
'Darwin' => OSX::of($clock, $control, $path),
'Linux' => Linux::of($clock, $control),
default => throw new \LogicException('Unsupported operating system '.\PHP_OS),
};
}
Expand Down
11 changes: 8 additions & 3 deletions src/Servers/Linux.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,18 @@ final class Linux implements Server
private LoadAverageFacade $loadAverage;
private UnixDisk $disk;

public function __construct(Clock $clock, Control $control)
private function __construct(Clock $clock, Control $control)
{
$this->cpu = new CpuFacade($control->processes());
$this->memory = new MemoryFacade($control->processes());
$this->processes = new UnixProcesses($clock, $control->processes());
$this->processes = UnixProcesses::of($clock, $control->processes());
$this->loadAverage = new LoadAverageFacade;
$this->disk = new UnixDisk($control->processes());
$this->disk = UnixDisk::of($control->processes());
}

public static function of(Clock $clock, Control $control): self
{
return new self($clock, $control);
}

#[\Override]
Expand Down
11 changes: 8 additions & 3 deletions src/Servers/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@ final class Logger implements Server
private Server $server;
private LoggerInterface $logger;

public function __construct(Server $server, LoggerInterface $logger)
private function __construct(Server $server, LoggerInterface $logger)
{
$this->server = $server;
$this->logger = $logger;
}

public static function of(Server $server, LoggerInterface $logger): self
{
return new self($server, $logger);
}

#[\Override]
public function cpu(): Attempt
{
Expand Down Expand Up @@ -58,7 +63,7 @@ public function memory(): Attempt
#[\Override]
public function processes(): Processes
{
return new Processes\LoggerProcesses(
return Processes\LoggerProcesses::of(
$this->server->processes(),
$this->logger,
);
Expand All @@ -81,7 +86,7 @@ public function loadAverage(): Attempt
#[\Override]
public function disk(): Disk
{
return new Disk\LoggerDisk(
return Disk\LoggerDisk::of(
$this->server->disk(),
$this->logger,
);
Expand Down
11 changes: 8 additions & 3 deletions src/Servers/OSX.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,18 @@ final class OSX implements Server
private LoadAverageFacade $loadAverage;
private UnixDisk $disk;

public function __construct(Clock $clock, Control $control, EnvironmentPath $path)
private function __construct(Clock $clock, Control $control, EnvironmentPath $path)
{
$this->cpu = new CpuFacade($control->processes());
$this->memory = new MemoryFacade($control->processes(), $path);
$this->processes = new UnixProcesses($clock, $control->processes());
$this->processes = UnixProcesses::of($clock, $control->processes());
$this->loadAverage = new LoadAverageFacade;
$this->disk = new UnixDisk($control->processes());
$this->disk = UnixDisk::of($control->processes());
}

public static function of(Clock $clock, Control $control, EnvironmentPath $path): self
{
return new self($clock, $control, $path);
}

#[\Override]
Expand Down
6 changes: 3 additions & 3 deletions tests/Server/Disk/LoggerDiskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@ class LoggerDiskTest extends TestCase
{
public function testInterface()
{
$this->assertInstanceOf(Disk::class, new LoggerDisk(
$this->assertInstanceOf(Disk::class, LoggerDisk::of(
$this->disk(),
new NullLogger,
));
}

public function testVolumes()
{
$disk = new LoggerDisk($this->disk(), new NullLogger);
$disk = LoggerDisk::of($this->disk(), new NullLogger);

$this->assertInstanceOf(Set::class, $disk->volumes());
}

public function testGet()
{
$disk = new LoggerDisk($this->disk(), new NullLogger);
$disk = LoggerDisk::of($this->disk(), new NullLogger);

$this->assertInstanceOf(Volume::class, $disk->get(MountPoint::of('/'))->match(
static fn($volume) => $volume,
Expand Down
2 changes: 1 addition & 1 deletion tests/Server/Disk/UnixDiskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class UnixDiskTest extends TestCase

public function setUp(): void
{
$this->disk = new UnixDisk(
$this->disk = UnixDisk::of(
Control::build(
Clock::live(),
IO::fromAmbientAuthority(),
Expand Down
6 changes: 3 additions & 3 deletions tests/Server/Processes/LoggerProcessesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@ class LoggerProcessesTest extends TestCase
{
public function testInterface()
{
$this->assertInstanceOf(Processes::class, new LoggerProcesses(
$this->assertInstanceOf(Processes::class, LoggerProcesses::of(
$this->processes(),
new NullLogger,
));
}

public function testAll()
{
$processes = new LoggerProcesses($this->processes(), new NullLogger);
$processes = LoggerProcesses::of($this->processes(), new NullLogger);

$this->assertInstanceOf(Set::class, $processes->all());
}

public function testGet()
{
$processes = new LoggerProcesses($this->processes(), new NullLogger);
$processes = LoggerProcesses::of($this->processes(), new NullLogger);

$this->assertInstanceOf(Process::class, $processes->get(Pid::of(1))->match(
static fn($process) => $process,
Expand Down
2 changes: 1 addition & 1 deletion tests/Server/Processes/UnixProcessesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class UnixProcessesTest extends TestCase

public function setUp(): void
{
$this->processes = new UnixProcesses(
$this->processes = UnixProcesses::of(
Clock::live(),
Control::build(
Clock::live(),
Expand Down
2 changes: 1 addition & 1 deletion tests/Servers/LinuxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class LinuxTest extends TestCase

public function setUp(): void
{
$this->server = new Linux(
$this->server = Linux::of(
Clock::live(),
Control::build(
Clock::live(),
Expand Down
14 changes: 7 additions & 7 deletions tests/Servers/LoggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ class LoggerTest extends TestCase
{
public function testInterface()
{
$this->assertInstanceOf(Server::class, new Logger(
$this->assertInstanceOf(Server::class, Logger::of(
$this->server(),
new NullLogger,
));
}

public function testCpu()
{
$server = new Logger($this->server(), new NullLogger);
$server = Logger::of($this->server(), new NullLogger);

$this->assertInstanceOf(Cpu::class, $server->cpu()->match(
static fn($cpu) => $cpu,
Expand All @@ -44,7 +44,7 @@ public function testCpu()

public function testMemory()
{
$server = new Logger($this->server(), new NullLogger);
$server = Logger::of($this->server(), new NullLogger);

$this->assertInstanceOf(Memory::class, $server->memory()->match(
static fn($memory) => $memory,
Expand All @@ -54,7 +54,7 @@ public function testMemory()

public function testProcesses()
{
$server = new Logger(
$server = Logger::of(
$this->server(),
new NullLogger,
);
Expand All @@ -64,14 +64,14 @@ public function testProcesses()

public function testLoadAverage()
{
$server = new Logger($this->server(), new NullLogger);
$server = Logger::of($this->server(), new NullLogger);

$this->assertInstanceOf(LoadAverage::class, $server->loadAverage()->unwrap());
}

public function testDisk()
{
$server = new Logger(
$server = Logger::of(
$this->server(),
new NullLogger,
);
Expand All @@ -81,7 +81,7 @@ public function testDisk()

public function testTmp()
{
$server = new Logger($this->server(), new NullLogger);
$server = Logger::of($this->server(), new NullLogger);

$this->assertInstanceOf(Path::class, $server->tmp());
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Servers/OSXTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class OSXTest extends TestCase

public function setUp(): void
{
$this->server = new OSX(
$this->server = OSX::of(
Clock::live(),
Control::build(
Clock::live(),
Expand Down