puli /
manager
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | /* |
||
| 4 | * This file is part of the puli/manager package. |
||
| 5 | * |
||
| 6 | * (c) Bernhard Schussek <[email protected]> |
||
| 7 | * |
||
| 8 | * For the full copyright and license information, please view the LICENSE |
||
| 9 | * file that was distributed with this source code. |
||
| 10 | */ |
||
| 11 | |||
| 12 | namespace Puli\Manager\Api\Module; |
||
| 13 | |||
| 14 | use Exception; |
||
| 15 | use Puli\Manager\Assert\Assert; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * A configured module. |
||
| 19 | * |
||
| 20 | * @since 1.0 |
||
| 21 | * |
||
| 22 | * @author Bernhard Schussek <[email protected]> |
||
| 23 | */ |
||
| 24 | class Module |
||
| 25 | { |
||
| 26 | /** |
||
| 27 | * @var string |
||
| 28 | */ |
||
| 29 | private $name; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var ModuleFile |
||
| 33 | */ |
||
| 34 | private $moduleFile; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var string |
||
| 38 | */ |
||
| 39 | private $installPath; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var InstallInfo |
||
| 43 | */ |
||
| 44 | private $installInfo; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @var int |
||
| 48 | */ |
||
| 49 | private $state; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @var Exception[] |
||
| 53 | */ |
||
| 54 | private $loadErrors; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Creates a new module. |
||
| 58 | * |
||
| 59 | * @param ModuleFile|null $moduleFile The module file or `null` if the |
||
| 60 | * module file could not be loaded. |
||
| 61 | * @param string $installPath The absolute install path. |
||
| 62 | * @param InstallInfo|null $installInfo The install info of this module. |
||
| 63 | * @param Exception[] $loadErrors The errors that happened during |
||
| 64 | * loading of the module, if any. |
||
| 65 | */ |
||
| 66 | 436 | public function __construct(ModuleFile $moduleFile = null, $installPath, InstallInfo $installInfo = null, array $loadErrors = array()) |
|
| 67 | { |
||
| 68 | 436 | Assert::absoluteSystemPath($installPath); |
|
| 69 | 436 | Assert::allIsInstanceOf($loadErrors, 'Exception'); |
|
| 70 | |||
| 71 | // If a module name was set during installation, that name wins over |
||
| 72 | // the predefined name in the puli.json file (if any) |
||
| 73 | 436 | $this->name = $installInfo && null !== $installInfo->getModuleName() |
|
| 74 | 173 | ? $installInfo->getModuleName() |
|
| 75 | 422 | : ($moduleFile ? $moduleFile->getModuleName() : null); |
|
| 76 | |||
| 77 | 436 | if (null === $this->name) { |
|
| 78 | 83 | $this->name = $this->getDefaultName(); |
|
|
0 ignored issues
–
show
|
|||
| 79 | } |
||
| 80 | |||
| 81 | // The path is stored both here and in the install info. While the |
||
| 82 | // install info contains the path as it is stored in the install file |
||
| 83 | // (i.e. relative or absolute), the install path of the module is |
||
| 84 | // always an absolute path. |
||
| 85 | 436 | $this->installPath = $installPath; |
|
| 86 | 436 | $this->installInfo = $installInfo; |
|
| 87 | 436 | $this->moduleFile = $moduleFile; |
|
| 88 | 436 | $this->loadErrors = $loadErrors; |
|
| 89 | |||
| 90 | 436 | if (!file_exists($installPath)) { |
|
| 91 | 248 | $this->state = ModuleState::NOT_FOUND; |
|
| 92 | 298 | } elseif (count($loadErrors) > 0) { |
|
| 93 | 5 | $this->state = ModuleState::NOT_LOADABLE; |
|
| 94 | } else { |
||
| 95 | 297 | $this->state = ModuleState::ENABLED; |
|
| 96 | } |
||
| 97 | 436 | } |
|
| 98 | |||
| 99 | /** |
||
| 100 | * Returns the name of the module. |
||
| 101 | * |
||
| 102 | * @return string The name of the module. |
||
| 103 | */ |
||
| 104 | 376 | public function getName() |
|
| 105 | { |
||
| 106 | 376 | return $this->name; |
|
| 107 | } |
||
| 108 | |||
| 109 | /** |
||
| 110 | * Returns the absolute path at which the module is installed. |
||
| 111 | * |
||
| 112 | * @return string The absolute install path of the module. |
||
| 113 | */ |
||
| 114 | 99 | public function getInstallPath() |
|
| 115 | { |
||
| 116 | 99 | return $this->installPath; |
|
| 117 | } |
||
| 118 | |||
| 119 | /** |
||
| 120 | * Returns the module file of the module. |
||
| 121 | * |
||
| 122 | * @return ModuleFile|null The module file or `null` if the file could not |
||
| 123 | * be loaded. |
||
| 124 | */ |
||
| 125 | 270 | public function getModuleFile() |
|
| 126 | { |
||
| 127 | 270 | return $this->moduleFile; |
|
| 128 | } |
||
| 129 | |||
| 130 | /** |
||
| 131 | * Returns the module's install info. |
||
| 132 | * |
||
| 133 | * @return InstallInfo The install info. |
||
| 134 | */ |
||
| 135 | 27 | public function getInstallInfo() |
|
| 136 | { |
||
| 137 | 27 | return $this->installInfo; |
|
| 138 | } |
||
| 139 | |||
| 140 | /** |
||
| 141 | * Returns the error that occurred during loading of the module. |
||
| 142 | * |
||
| 143 | * @return Exception[] The errors or an empty array if the module was |
||
| 144 | * loaded successfully. |
||
| 145 | */ |
||
| 146 | 11 | public function getLoadErrors() |
|
| 147 | { |
||
| 148 | 11 | return $this->loadErrors; |
|
| 149 | } |
||
| 150 | |||
| 151 | /** |
||
| 152 | * Returns the state of the module. |
||
| 153 | * |
||
| 154 | * @return int One of the {@link ModuleState} constants. |
||
| 155 | */ |
||
| 156 | 3 | public function getState() |
|
| 157 | { |
||
| 158 | 3 | return $this->state; |
|
| 159 | } |
||
| 160 | |||
| 161 | /** |
||
| 162 | * Returns whether the module is enabled. |
||
| 163 | * |
||
| 164 | * @return bool Returns `true` if the state is {@link ModuleState::ENABLED}. |
||
| 165 | * |
||
| 166 | * @see ModuleState::ENABLED |
||
| 167 | */ |
||
| 168 | 5 | public function isEnabled() |
|
| 169 | { |
||
| 170 | 5 | return ModuleState::ENABLED === $this->state; |
|
| 171 | } |
||
| 172 | |||
| 173 | /** |
||
| 174 | * Returns whether the module was not found. |
||
| 175 | * |
||
| 176 | * @return bool Returns `true` if the state is {@link ModuleState::NOT_FOUND}. |
||
| 177 | * |
||
| 178 | * @see ModuleState::NOT_FOUND |
||
| 179 | */ |
||
| 180 | 1 | public function isNotFound() |
|
| 181 | { |
||
| 182 | 1 | return ModuleState::NOT_FOUND === $this->state; |
|
| 183 | } |
||
| 184 | |||
| 185 | /** |
||
| 186 | * Returns whether the module was not loadable. |
||
| 187 | * |
||
| 188 | * @return bool Returns `true` if the state is {@link ModuleState::NOT_LOADABLE}. |
||
| 189 | * |
||
| 190 | * @see ModuleState::NOT_LOADABLE |
||
| 191 | */ |
||
| 192 | 3 | public function isNotLoadable() |
|
| 193 | { |
||
| 194 | 3 | return ModuleState::NOT_LOADABLE === $this->state; |
|
| 195 | } |
||
| 196 | |||
| 197 | /** |
||
| 198 | * Returns the default name of a module. |
||
| 199 | */ |
||
| 200 | 72 | protected function getDefaultName() |
|
| 201 | { |
||
| 202 | 72 | return null; |
|
| 203 | } |
||
| 204 | } |
||
| 205 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.