src/PeekAndPoke/Aviator/ServiceContainer/ServiceContainerCodeGenerator.php
private function generateFactoryCreatorMethod(FactoredService $service) : string
    {
        $factoryMethod = $service->getFactoryMethod();
        $taggedAs      = implode(', ', $service->getTags());

        $classNormalized = $this->normalizeFqcn($service->getClass());
        $optional        = $service->getFactoryMethod()->isOptional() ? '?' : '';

        ////  SINGLETON  ////////////////////////////////////////////////////////////////////////////////////////////

        if ($service->isSingleton()) {

            return <<<PHP
    /**
     * Get the factored service "{$service->getId()}" (Singleton)
     *
     * It is tagged as: {$taggedAs}
     *
     * @return {$this->normalizeFqcn($service->getClass())}
     */
    public function {$this->mapIdToServiceGetter($service->getId())} () : {$optional}{$classNormalized} 
    {
        if (isset(\$this->singletons['{$service->getId()}'])) {
            return \$this->singletons['{$service->getId()}'];
        }

        /** @noinspection OneTimeUseVariablesInspection */
        \$service = \$this->singletons['{$service->getId()}'] = {$this->generateCreatorByServiceId($factoryMethod->getFactoryId())}->{$factoryMethod->getMethodName()}(
{$this->buildInjectionParameters($this->container, $factoryMethod->getInjection())}
        );

{$this->generateSetterInjectionsCode($service)}

        return \$service;
    }

PHP;
        }

        ////  PROTOTYPE  ////////////////////////////////////////////////////////////////////////////////////////////

        return <<<PHP
    /**
     * Get a fresh instance of service "{$service->getId()}" (Prototype)
     *
     * It is tagged as: {$taggedAs}
     *
     * @return {$this->normalizeFqcn($service->getClass())}
     */
    public function {$this->mapIdToServiceGetter($service->getId())} () : $classNormalized 
    {
        \$this->prototypes['{$service->getId()}'] = (\$this->prototypes['{$service->getId()}'] ?? 0) + 1;

        /** @noinspection OneTimeUseVariablesInspection */
        \$service = {$this->generateCreatorByServiceId($factoryMethod->getFactoryId())}->{$factoryMethod->getMethodName()}(
{$this->buildInjectionParameters($this->container, $factoryMethod->getInjection())}
        );

{$this->generateSetterInjectionsCode($service)}

        return \$service;
    }

PHP;

    }
private function generateFactoryCreatorMethod(FactoredService $service) : string
    {
        $factoryMethod = $service->getFactoryMethod();
        $taggedAs      = implode(', ', $service->getTags());

        $classNormalized = $this->normalizeFqcn($service->getClass());
        $optional        = $service->getFactoryMethod()->isOptional() ? '?' : '';

        ////  SINGLETON  ////////////////////////////////////////////////////////////////////////////////////////////

        if ($service->isSingleton()) {

            return <<<PHP
    /**
     * Get the factored service "{$service->getId()}" (Singleton)
     *
     * It is tagged as: {$taggedAs}
     *
     * @return {$this->normalizeFqcn($service->getClass())}
     */
    public function {$this->mapIdToServiceGetter($service->getId())} () : {$optional}{$classNormalized} 
    {
        if (isset(\$this->singletons['{$service->getId()}'])) {
            return \$this->singletons['{$service->getId()}'];
        }

        /** @noinspection OneTimeUseVariablesInspection */
        \$service = \$this->singletons['{$service->getId()}'] = {$this->generateCreatorByServiceId($factoryMethod->getFactoryId())}->{$factoryMethod->getMethodName()}(
{$this->buildInjectionParameters($this->container, $factoryMethod->getInjection())}
        );

{$this->generateSetterInjectionsCode($service)}

        return \$service;
    }

PHP;
        }

        ////  PROTOTYPE  ////////////////////////////////////////////////////////////////////////////////////////////

        return <<<PHP
    /**
     * Get a fresh instance of service "{$service->getId()}" (Prototype)
     *
     * It is tagged as: {$taggedAs}
     *
     * @return {$this->normalizeFqcn($service->getClass())}
     */
    public function {$this->mapIdToServiceGetter($service->getId())} () : $classNormalized 
    {
        \$this->prototypes['{$service->getId()}'] = (\$this->prototypes['{$service->getId()}'] ?? 0) + 1;

        /** @noinspection OneTimeUseVariablesInspection */
        \$service = {$this->generateCreatorByServiceId($factoryMethod->getFactoryId())}->{$factoryMethod->getMethodName()}(
{$this->buildInjectionParameters($this->container, $factoryMethod->getInjection())}
        );

{$this->generateSetterInjectionsCode($service)}

        return \$service;
    }

PHP;

    }
Generates the creator method for a service that is provided by a factory method

@param FactoredService $service

@return string