Skip to content

Commit

Permalink
Stack-trace was removed from error showing. Added phpcs:ignoreFile
Browse files Browse the repository at this point in the history
- For showing stack trace should be in charge of another instruments like: whoops.
- Added Makefile for local manipulation.
  • Loading branch information
renakdup committed Apr 6, 2024
1 parent a7e4f66 commit 679dc3a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

d.run:
docker run --rm -it -v "${PWD}":/usr/src/myapp -w /usr/src/myapp pimlab/composer:2.0.0-alpha3-php7.4 sh
23 changes: 7 additions & 16 deletions src/Container.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php // phpcs:ignoreFile
/**
* Simple PHP DIC - DI Container in one file.
* Supports autowiring and allows you to easily use it in your simple PHP applications and
Expand All @@ -8,7 +8,7 @@
* Author Email: [email protected]
* Author Site: https://wp-yoda.com/en/
*
* Version: 0.2.4
* Version: 0.2.5
* Source Code: https://github.com/renakdup/simple-php-dic
*
* Licence: MIT License
Expand Down Expand Up @@ -98,7 +98,7 @@ class Container implements ContainerInterface {
public function __construct() {
// Auto-register the container
$this->resolved = [
self::class => $this,
self::class => $this,
ContainerInterface::class => $this,
];
}
Expand Down Expand Up @@ -147,9 +147,7 @@ public function has( string $id ): bool {
*/
public function make( string $id ): object {
if ( ! class_exists( $id ) ) {
$message = "Service '{$id}' could not be resolved because class not exist.\n"
. "Stack trace: \n"
. $this->get_stack_trace();
$message = "Service `{$id}` could not be resolved because class not exist.";
throw new ContainerException( $message );
}

Expand Down Expand Up @@ -178,10 +176,7 @@ protected function resolve( string $id ) {
return $this->resolve_object( $id );
}

$message = "Service '{$id}' not found in the Container.\n"
. "Stack trace: \n"
. $this->get_stack_trace();
throw new ContainerNotFoundException( $message );
throw new ContainerNotFoundException( "Service `{$id}` not found in the Container." );
}

/**
Expand Down Expand Up @@ -211,9 +206,7 @@ protected function resolve_object( string $service ): object {

} catch ( ReflectionException $e ) {
throw new ContainerException(
"Service '{$service}' could not be resolved due the reflection issue: '" . $e->getMessage() . "'\n" .
"Stack trace: \n" .
$e->getTraceAsString()
"Service `{$service}` could not be resolved due the reflection issue: `{$e->getMessage()}`"
);
}

Expand Down Expand Up @@ -253,9 +246,7 @@ protected function resolve_parameter( ReflectionParameter $param ) {
}

// @phpstan-ignore-next-line - Cannot call method getName() on ReflectionClass|null.
$message = "Parameter '{$param->getName()}' of '{$param->getDeclaringClass()->getName()}' cannot be resolved.\n" .
"Stack trace: \n" .
$this->get_stack_trace();
$message = "Parameter `{$param->getName()}` of `{$param->getDeclaringClass()->getName()}` can't be resolved.";
throw new ContainerException( $message );
}

Expand Down

0 comments on commit 679dc3a

Please sign in to comment.