| Conditions | 1 |
| Total Lines | 89 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php declare(strict_types=1); |
||
| 74 | private function getContainerForNamespace(string $namespace): ContainerBuilder |
||
| 75 | { |
||
| 76 | if (isset($this->generatedContainerClass[$namespace])) { |
||
| 77 | return $this->generatedContainerClass[$namespace]; |
||
| 78 | } |
||
| 79 | |||
| 80 | $containerBuilder = new ContainerBuilder(); |
||
| 81 | $pathToFiles = $this->copiedWorkDir . '/src/'; |
||
| 82 | $fileLocator = new FileLocator($pathToFiles); |
||
| 83 | |||
| 84 | $loader = new class($containerBuilder, $fileLocator, $namespace, $pathToFiles) extends FileLoader |
||
| 85 | { |
||
| 86 | /** |
||
| 87 | * @var string |
||
| 88 | */ |
||
| 89 | private $namespace; |
||
| 90 | /** |
||
| 91 | * @var string |
||
| 92 | */ |
||
| 93 | private $pathToFiles; |
||
| 94 | |||
| 95 | public function __construct( |
||
| 96 | ContainerBuilder $container, |
||
| 97 | FileLocatorInterface $locator, |
||
| 98 | string $namespace, |
||
| 99 | string $pathToFiles |
||
| 100 | ) { |
||
| 101 | parent::__construct($container, $locator); |
||
| 102 | $this->namespace = $namespace . '\\'; |
||
| 103 | $this->pathToFiles = str_replace('//', '/', $pathToFiles . '/*'); |
||
| 104 | } |
||
| 105 | |||
| 106 | /** |
||
| 107 | * Loads a resource. |
||
| 108 | * |
||
| 109 | * @param mixed $resource The resource |
||
| 110 | * @param string|null $type The resource type or null if unknown |
||
| 111 | * |
||
| 112 | * @throws \Exception If something went wrong |
||
| 113 | * |
||
| 114 | */ |
||
| 115 | public function load($resource, $type = null): void |
||
| 116 | { |
||
| 117 | $definition = new Definition(); |
||
| 118 | |||
| 119 | $definition->setAutowired(true)->setAutoconfigured(true)->setPublic(true); |
||
| 120 | $this->registerClasses($definition, $this->namespace, $this->pathToFiles); |
||
| 121 | $dsmContainer = new Container(); |
||
| 122 | $dsmContainer->addConfiguration($this->container, $this->buildServerConfig()); |
||
| 123 | $this->container->compile(); |
||
| 124 | } |
||
| 125 | |||
| 126 | /** |
||
| 127 | * @return array |
||
| 128 | */ |
||
| 129 | private function buildServerConfig() |
||
| 130 | { |
||
| 131 | SimpleEnv::setEnv(Config::getProjectRootDirectory() . '/.env'); |
||
| 132 | $testConfig = $_SERVER; |
||
| 133 | $testConfig[ConfigInterface::PARAM_DB_NAME] .= '_test'; |
||
| 134 | $testConfig[ConfigInterface::PARAM_DEVMODE] = true; |
||
| 135 | |||
| 136 | return $testConfig; |
||
| 137 | } |
||
| 138 | |||
| 139 | /** |
||
| 140 | * Returns whether this class supports the given resource. |
||
| 141 | * |
||
| 142 | * @param mixed $resource A resource |
||
| 143 | * @param string|null $type The resource type or null if unknown |
||
| 144 | * |
||
| 145 | * @return bool True if this class supports the given resource, false otherwise |
||
| 146 | */ |
||
| 147 | public function supports($resource, $type = null): bool |
||
| 148 | { |
||
| 149 | return true; |
||
| 150 | } |
||
| 151 | |||
| 152 | public function getContainer(): ContainerBuilder |
||
| 153 | { |
||
| 154 | return $this->container; |
||
| 155 | } |
||
| 156 | }; |
||
| 157 | |||
| 158 | $loader->load('required by the interface'); |
||
| 159 | |||
| 160 | $this->generatedContainerClass[$namespace] = $loader->getContainer(); |
||
| 161 | |||
| 162 | return $this->generatedContainerClass[$namespace]; |
||
| 163 | } |
||
| 165 |