Skip to content

Commit

Permalink
non final inspector
Browse files Browse the repository at this point in the history
  • Loading branch information
rodber committed Mar 2, 2024
1 parent 48a9049 commit 9a5dc40
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 124 deletions.
68 changes: 65 additions & 3 deletions src/Inspector.php
Expand Up @@ -13,10 +13,72 @@

namespace Chevere\xrDebug\PHP;

use Chevere\xrDebug\PHP\Interfaces\ClientInterface;
use Chevere\xrDebug\PHP\Interfaces\InspectorInterface;
use Chevere\xrDebug\PHP\Traits\InspectorTrait;
use Throwable;

final class Inspector implements InspectorInterface
class Inspector implements InspectorInterface
{
use InspectorTrait;
public function __construct(
protected ClientInterface $client,
) {
}

public function pause(
string $t = '',
string $e = '',
int $f = 0,
): void {
$this->command(
action: 'sendPause',
topic: $t,
emote: $e,
flags: $f,
);
}

public function memory(
string $t = '',
string $e = '',
int $f = 0,
): void {
$memory = memory_get_usage(true);
$body = sprintf('%.2F MB', $memory / 1000000);
$this->command(
action: 'sendMessage',
body: $body,
topic: $t,
emote: $e,
flags: $f,
);
}

protected function command(
string $action,
string $body = '',
string $topic = '',
string $emote = '',
int $flags = 0
): void {
$backtrace = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, 2);
array_shift($backtrace);
$message = new Message(backtrace: $backtrace);
$message = $message
->withBody($body)
->withTopic($topic)
->withEmote($emote)
->withFlags($flags);

try {
$this->client->{$action}($message);
} catch (Throwable $e) {
if (PHP_SAPI === 'cli') {
echo <<<PLAIN
* {$e->getMessage()}
PLAIN;
$this->client->exit(255);
}
}
}
}
19 changes: 16 additions & 3 deletions src/InspectorNull.php
Expand Up @@ -14,9 +14,22 @@
namespace Chevere\xrDebug\PHP;

use Chevere\xrDebug\PHP\Interfaces\InspectorInterface;
use Chevere\xrDebug\PHP\Traits\InspectorNullTrait;

final class InspectorNull implements InspectorInterface
class InspectorNull implements InspectorInterface
{
use InspectorNullTrait;
public function pause(
string $e = '',
string $t = '',
int $f = 0,

Check warning on line 23 in src/InspectorNull.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 test on ubuntu-latest

Escaped Mutant for Mutator "DecrementInteger": --- Original +++ New @@ @@ use Chevere\xrDebug\PHP\Interfaces\InspectorInterface; class InspectorNull implements InspectorInterface { - public function pause(string $e = '', string $t = '', int $f = 0) : void + public function pause(string $e = '', string $t = '', int $f = -1) : void { // null }

Check warning on line 23 in src/InspectorNull.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 test on ubuntu-latest

Escaped Mutant for Mutator "IncrementInteger": --- Original +++ New @@ @@ use Chevere\xrDebug\PHP\Interfaces\InspectorInterface; class InspectorNull implements InspectorInterface { - public function pause(string $e = '', string $t = '', int $f = 0) : void + public function pause(string $e = '', string $t = '', int $f = 1) : void { // null }

Check warning on line 23 in src/InspectorNull.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 test on ubuntu-latest

Escaped Mutant for Mutator "DecrementInteger": --- Original +++ New @@ @@ use Chevere\xrDebug\PHP\Interfaces\InspectorInterface; class InspectorNull implements InspectorInterface { - public function pause(string $e = '', string $t = '', int $f = 0) : void + public function pause(string $e = '', string $t = '', int $f = -1) : void { // null }

Check warning on line 23 in src/InspectorNull.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 test on ubuntu-latest

Escaped Mutant for Mutator "IncrementInteger": --- Original +++ New @@ @@ use Chevere\xrDebug\PHP\Interfaces\InspectorInterface; class InspectorNull implements InspectorInterface { - public function pause(string $e = '', string $t = '', int $f = 0) : void + public function pause(string $e = '', string $t = '', int $f = 1) : void { // null }

Check warning on line 23 in src/InspectorNull.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 test on ubuntu-latest

Escaped Mutant for Mutator "DecrementInteger": --- Original +++ New @@ @@ use Chevere\xrDebug\PHP\Interfaces\InspectorInterface; class InspectorNull implements InspectorInterface { - public function pause(string $e = '', string $t = '', int $f = 0) : void + public function pause(string $e = '', string $t = '', int $f = -1) : void { // null }

Check warning on line 23 in src/InspectorNull.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 test on ubuntu-latest

Escaped Mutant for Mutator "IncrementInteger": --- Original +++ New @@ @@ use Chevere\xrDebug\PHP\Interfaces\InspectorInterface; class InspectorNull implements InspectorInterface { - public function pause(string $e = '', string $t = '', int $f = 0) : void + public function pause(string $e = '', string $t = '', int $f = 1) : void { // null }
): void {
// null
}

public function memory(
string $e = '',
string $t = '',
int $f = 0,

Check warning on line 31 in src/InspectorNull.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 test on ubuntu-latest

Escaped Mutant for Mutator "DecrementInteger": --- Original +++ New @@ @@ { // null } - public function memory(string $e = '', string $t = '', int $f = 0) : void + public function memory(string $e = '', string $t = '', int $f = -1) : void { // null } }

Check warning on line 31 in src/InspectorNull.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 test on ubuntu-latest

Escaped Mutant for Mutator "IncrementInteger": --- Original +++ New @@ @@ { // null } - public function memory(string $e = '', string $t = '', int $f = 0) : void + public function memory(string $e = '', string $t = '', int $f = 1) : void { // null } }

Check warning on line 31 in src/InspectorNull.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 test on ubuntu-latest

Escaped Mutant for Mutator "DecrementInteger": --- Original +++ New @@ @@ { // null } - public function memory(string $e = '', string $t = '', int $f = 0) : void + public function memory(string $e = '', string $t = '', int $f = -1) : void { // null } }

Check warning on line 31 in src/InspectorNull.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 test on ubuntu-latest

Escaped Mutant for Mutator "IncrementInteger": --- Original +++ New @@ @@ { // null } - public function memory(string $e = '', string $t = '', int $f = 0) : void + public function memory(string $e = '', string $t = '', int $f = 1) : void { // null } }

Check warning on line 31 in src/InspectorNull.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 test on ubuntu-latest

Escaped Mutant for Mutator "DecrementInteger": --- Original +++ New @@ @@ { // null } - public function memory(string $e = '', string $t = '', int $f = 0) : void + public function memory(string $e = '', string $t = '', int $f = -1) : void { // null } }

Check warning on line 31 in src/InspectorNull.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 test on ubuntu-latest

Escaped Mutant for Mutator "IncrementInteger": --- Original +++ New @@ @@ { // null } - public function memory(string $e = '', string $t = '', int $f = 0) : void + public function memory(string $e = '', string $t = '', int $f = 1) : void { // null } }
): void {
// null
}
}
36 changes: 0 additions & 36 deletions src/Traits/InspectorNullTrait.php

This file was deleted.

82 changes: 0 additions & 82 deletions src/Traits/InspectorTrait.php

This file was deleted.

0 comments on commit 9a5dc40

Please sign in to comment.