Skip to content

Commit

Permalink
Improved phpdocs with new docblocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
feuzeu committed Feb 9, 2025
1 parent 3343730 commit 7ce06c4
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 61 deletions.
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ namespace App\Facades;
use App\Services\MyService;
use Lagdo\Symfony\Facades\AbstractFacade;

/**
* @extends AbstractFacade<MyService>
*/
class MyFacade extends AbstractFacade
{
/**
Expand Down Expand Up @@ -80,6 +83,8 @@ class TheService
}
```

The `@extends AbstractFacade<MyService>` phpdoc will prevent errors during code analysis with [PHPStan](https://phpstan.org/), and allow code completion on calls to facades in editors.

### Using a service locator

The above facade will work only for services that are declared as public.
Expand Down Expand Up @@ -108,15 +113,19 @@ A facade can then be defined for the `Twig` service.
namespace App\Facades;
use Lagdo\Symfony\Facades\AbstractFacade;
use Twig\Environment;
/**
* @extends AbstractFacade<Environment>
*/
class View extends AbstractFacade
{
/**
* @inheritdoc
*/
protected static function getServiceIdentifier(): string
{
return \Twig\Environment::class;
return Environment::class;
}
}
```
Expand All @@ -143,7 +152,7 @@ Starting from version 2.3.0, the private services that need to be accessed with

These services will then be automatically passed to the service locator, together with those received as arguments.

In the following example, the `App\Services\TaggedService` service will be passed to the service locator.
In the following example, the `Twig` and `App\Services\TaggedService` services will be passed to the service locator.

```yaml
lagdo.facades.service_locator:
Expand All @@ -167,6 +176,9 @@ namespace App\Facades;
use App\Services\TaggedService;
use Lagdo\Symfony\Facades\AbstractFacade;
/**
* @extends AbstractFacade<TaggedService>
*/
class TaggedServiceFacade extends AbstractFacade
{
/**
Expand Down Expand Up @@ -211,6 +223,9 @@ use App\Services\MyService;
use Lagdo\Symfony\Facades\AbstractFacade;
use Lagdo\Symfony\Facades\ServiceInstance;
/**
* @extends AbstractFacade<MyService>
*/
class MyFacade extends AbstractFacade
{
use ServiceInstance;
Expand Down
6 changes: 5 additions & 1 deletion src/AbstractFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

namespace Lagdo\Symfony\Facades;

/**
* @template Service of object
* @mixin Service
*/
abstract class AbstractFacade
{
/**
Expand All @@ -14,7 +18,7 @@ abstract protected static function getServiceIdentifier(): string;
/**
* Get the service instance.
*
* @return mixed
* @return Service
*/
public static function instance()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ public static function getFacadeService(string $serviceId)
self::$container->get($serviceId) :
// If not found in the container, then look in the service locator.
(self::$locator !== null && self::$locator->has($serviceId) ?
self::$locator->get($serviceId) : null);
self::$locator->get($serviceId) : null);
}
}
10 changes: 1 addition & 9 deletions src/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,7 @@
use Psr\Log\LoggerInterface;

/**
* @method static void emergency(string|\Stringable $message, array $context = [])
* @method static void alert(string|\Stringable $message, array $context = [])
* @method static void critical(string|\Stringable $message, array $context = [])
* @method static void error(string|\Stringable $message, array $context = [])
* @method static void warning(string|\Stringable $message, array $context = [])
* @method static void notice(string|\Stringable $message, array $context = [])
* @method static void info(string|\Stringable $message, array $context = [])
* @method static void debug(string|\Stringable $message, array $context = [])
* @method static void log($level, string|\Stringable $message, array $context = [])
* @extends AbstractFacade<LoggerInterface>
*/
final class Log extends AbstractFacade
{
Expand Down
49 changes: 1 addition & 48 deletions src/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,10 @@

namespace Lagdo\Symfony\Facades;

use Twig\Extension\ExtensionInterface;
use Twig\Loader\LoaderInterface;
use Twig\NodeVisitor\NodeVisitorInterface;
use Twig\RuntimeLoader\RuntimeLoaderInterface;
use Twig\TokenParser\TokenParserInterface;
use Twig\Cache\CacheInterface;
use Twig\TemplateWrapper;
use Twig\Template;
use Twig\TwigFilter;
use Twig\TwigTest;
use Twig\TwigFunction;
use Twig\Environment;
use Lagdo\Symfony\Facades\AbstractFacade;

/**
* @method static void enableDebug()
* @method static void disableDebug()
* @method static bool isDebug()
* @method static void enableAutoReload()
* @method static void disableAutoReload()
* @method static bool isAutoReload()
* @method static void enableStrictVariables()
* @method static bool isStrictVariables()
* @method static CacheInterface|string|false getCache(bool $original = true)
* @method static void setCache(CacheInterface|string|false $cache)
* @method static string render(string|TemplateWrapper $name, array $context = [])
* @method static string display(string|TemplateWrapper $name, array $context = [])
* @method static TemplateWrapper load(string|TemplateWrapper $name)
* @method static TemplateWrapper createTemplate(string $template, string $name = null)
* @method static bool isTemplateFresh(string $name, int $time)
* @method static TemplateWrapper|Template resolveTemplate(string|TemplateWrapper|array $names)
* @method static void setLoader(LoaderInterface $loader)
* @method static LoaderInterface getLoader()
* @method static void addRuntimeLoader(RuntimeLoaderInterface $loader)
* @method static object getRuntime(string $class)
* @method static void setCharset(string $charset)
* @method static string getCharset()
* @method static bool hasExtension(string $class)
* @method static ExtensionInterface getExtension(string $class)
* @method static void addExtension(ExtensionInterface $extension)
* @method static void setExtensions(array $extensions)
* @method static ExtensionInterface[] getExtensions()
* @method static TokenParserInterface[] getTags()
* @method static void addNodeVisitor(NodeVisitorInterface $visitor)
* @method static void addFilter(TwigFilter $filter)
* @method static void registerUndefinedFilterCallback(callable $callable)
* @method static void addTest(TwigTest $test)
* @method static void addFunction(TwigFunction $function)
* @method static void registerUndefinedFunctionCallback(callable $callable)
* @method static void addGlobal(string $name, mixed $value)
* @method static array mergeGlobals(array $context)
* @extends AbstractFacade<Environment>
*/
final class View extends AbstractFacade
{
Expand Down
3 changes: 3 additions & 0 deletions tests/Facades/Instance/PrivateServiceFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
use Lagdo\Symfony\Facades\ServiceInstance;
use Lagdo\Symfony\Facades\Tests\Service\PrivateServiceInterface;

/**
* @extends AbstractFacade<PrivateServiceInterface>
*/
class PrivateServiceFacade extends AbstractFacade
{
use ServiceInstance;
Expand Down
3 changes: 3 additions & 0 deletions tests/Facades/Instance/PublicServiceFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
use Lagdo\Symfony\Facades\ServiceInstance;
use Lagdo\Symfony\Facades\Tests\Service\PublicServiceInterface;

/**
* @extends AbstractFacade<PublicServiceInterface>
*/
class PublicServiceFacade extends AbstractFacade
{
use ServiceInstance;
Expand Down
3 changes: 3 additions & 0 deletions tests/Facades/PrivateServiceFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
use Lagdo\Symfony\Facades\AbstractFacade;
use Lagdo\Symfony\Facades\Tests\Service\PrivateServiceInterface;

/**
* @extends AbstractFacade<PrivateServiceInterface>
*/
class PrivateServiceFacade extends AbstractFacade
{
/**
Expand Down
3 changes: 3 additions & 0 deletions tests/Facades/PublicServiceFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
use Lagdo\Symfony\Facades\AbstractFacade;
use Lagdo\Symfony\Facades\Tests\Service\PublicServiceInterface;

/**
* @extends AbstractFacade<PublicServiceInterface>
*/
class PublicServiceFacade extends AbstractFacade
{
/**
Expand Down
3 changes: 3 additions & 0 deletions tests/Facades/TaggedServiceFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
use Lagdo\Symfony\Facades\AbstractFacade;
use Lagdo\Symfony\Facades\Tests\Service\TaggedService;

/**
* @extends AbstractFacade<TaggedService>
*/
class TaggedServiceFacade extends AbstractFacade
{
/**
Expand Down

0 comments on commit 7ce06c4

Please sign in to comment.