ARCANEDEV /
Composer
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 namespace Arcanedev\Composer\Entities; |
||
| 2 | |||
| 3 | use Arcanedev\Composer\Utilities\Logger; |
||
| 4 | use Composer\Composer; |
||
| 5 | use Composer\Package\BasePackage; |
||
| 6 | use Composer\Package\Link; |
||
| 7 | use Composer\Package\RootAliasPackage; |
||
| 8 | use Composer\Package\RootPackageInterface; |
||
| 9 | use Composer\Package\Version\VersionParser; |
||
| 10 | |||
| 11 | /** |
||
| 12 | * Class Package |
||
| 13 | * |
||
| 14 | * @package Arcanedev\Composer\Entities |
||
| 15 | * @author ARCANEDEV <[email protected]> |
||
| 16 | */ |
||
| 17 | class Package |
||
| 18 | { |
||
| 19 | /* ----------------------------------------------------------------- |
||
| 20 | | Traits |
||
| 21 | | ----------------------------------------------------------------- |
||
| 22 | */ |
||
| 23 | |||
| 24 | use PackageTraits\RepositoriesTrait, |
||
| 25 | PackageTraits\RequiresTrait, |
||
| 26 | PackageTraits\AutoloadTrait, |
||
| 27 | PackageTraits\LinksTrait, |
||
| 28 | PackageTraits\SuggestsTrait, |
||
| 29 | PackageTraits\ExtraTrait, |
||
| 30 | PackageTraits\ScriptsTrait, |
||
| 31 | PackageTraits\DevTrait, |
||
| 32 | PackageTraits\ReferencesTrait; |
||
| 33 | |||
| 34 | /* ----------------------------------------------------------------- |
||
| 35 | | Properties |
||
| 36 | | ----------------------------------------------------------------- |
||
| 37 | */ |
||
| 38 | |||
| 39 | /** @var \Composer\Composer $composer */ |
||
| 40 | protected $composer; |
||
| 41 | |||
| 42 | /** @var \Arcanedev\Composer\Utilities\Logger $logger */ |
||
| 43 | protected $logger; |
||
| 44 | |||
| 45 | /** @var \Composer\Package\CompletePackage $package */ |
||
| 46 | protected $package; |
||
| 47 | |||
| 48 | /** @var string $path */ |
||
| 49 | protected $path; |
||
| 50 | |||
| 51 | /** @var \Composer\Package\Version\VersionParser $versionParser */ |
||
| 52 | protected $versionParser; |
||
| 53 | |||
| 54 | /** @var array $json */ |
||
| 55 | protected $json; |
||
| 56 | |||
| 57 | /* ----------------------------------------------------------------- |
||
| 58 | | Constructor |
||
| 59 | | ----------------------------------------------------------------- |
||
| 60 | */ |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Make a Package instance. |
||
| 64 | * |
||
| 65 | * @param string $path |
||
| 66 | * @param \Composer\Composer $composer |
||
| 67 | * @param \Arcanedev\Composer\Utilities\Logger $logger |
||
| 68 | */ |
||
| 69 | 99 | public function __construct($path, Composer $composer, Logger $logger) |
|
| 70 | { |
||
| 71 | 99 | $this->path = $path; |
|
| 72 | 99 | $this->composer = $composer; |
|
| 73 | 99 | $this->logger = $logger; |
|
| 74 | 99 | $this->json = PackageJson::read($path); |
|
| 75 | 99 | $this->package = PackageJson::convert($this->json); |
|
| 76 | 99 | $this->versionParser = new VersionParser; |
|
| 77 | 99 | } |
|
| 78 | |||
| 79 | /* ----------------------------------------------------------------- |
||
| 80 | | Getters & Setters |
||
| 81 | | ----------------------------------------------------------------- |
||
| 82 | */ |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Get list of additional packages to require if precessing recursively. |
||
| 86 | * |
||
| 87 | * @return array |
||
| 88 | */ |
||
| 89 | 96 | public function getRequires() |
|
| 90 | { |
||
| 91 | 96 | return $this->getJson()['extra']['merge-plugin']['require'] ?? []; |
|
| 92 | } |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Get list of additional packages to include if precessing recursively. |
||
| 96 | * |
||
| 97 | * @return array |
||
| 98 | */ |
||
| 99 | 96 | public function getIncludes() |
|
| 100 | { |
||
| 101 | 96 | return $this->getJson()['extra']['merge-plugin']['include'] ?? []; |
|
| 102 | } |
||
| 103 | |||
| 104 | /** |
||
| 105 | * Get composer. |
||
| 106 | * |
||
| 107 | * @return \Composer\Composer |
||
| 108 | */ |
||
| 109 | 12 | public function getComposer() |
|
| 110 | { |
||
| 111 | 12 | return $this->composer; |
|
| 112 | } |
||
| 113 | |||
| 114 | /** |
||
| 115 | * Get the Logger. |
||
| 116 | * |
||
| 117 | * @return \Arcanedev\Composer\Utilities\Logger |
||
| 118 | */ |
||
| 119 | 60 | public function getLogger() |
|
| 120 | { |
||
| 121 | 60 | return $this->logger; |
|
| 122 | } |
||
| 123 | |||
| 124 | /** |
||
| 125 | * Get the json. |
||
| 126 | * |
||
| 127 | * @return array |
||
| 128 | */ |
||
| 129 | 99 | public function getJson() |
|
| 130 | { |
||
| 131 | 99 | return $this->json; |
|
| 132 | } |
||
| 133 | |||
| 134 | /** |
||
| 135 | * Get the package. |
||
| 136 | * |
||
| 137 | * @return \Composer\Package\CompletePackage |
||
| 138 | */ |
||
| 139 | 99 | public function getPackage() |
|
| 140 | { |
||
| 141 | 99 | return $this->package; |
|
| 142 | } |
||
| 143 | |||
| 144 | /** |
||
| 145 | * Get the path. |
||
| 146 | * |
||
| 147 | * @return string |
||
| 148 | */ |
||
| 149 | 12 | public function getPath() |
|
| 150 | { |
||
| 151 | 12 | return $this->path; |
|
| 152 | } |
||
| 153 | |||
| 154 | /* ------------------------------------------------------------------------------------------------ |
||
| 155 | | Main Functions |
||
| 156 | | ------------------------------------------------------------------------------------------------ |
||
| 157 | */ |
||
| 158 | /** |
||
| 159 | * Merge this package into a RootPackage. |
||
| 160 | * |
||
| 161 | * @param \Composer\Package\RootPackageInterface $root |
||
| 162 | * @param \Arcanedev\Composer\Entities\PluginState $state |
||
| 163 | */ |
||
| 164 | 99 | public function mergeInto(RootPackageInterface $root, PluginState $state) |
|
| 165 | { |
||
| 166 | 99 | $this->prependRepositories($root); |
|
| 167 | 99 | $this->mergeRequires($root, $state); |
|
| 168 | 99 | $this->mergeAutoload($root); |
|
| 169 | 99 | $this->mergePackageLinks('conflict', $root); |
|
| 170 | 99 | $this->mergePackageLinks('replace', $root); |
|
| 171 | 99 | $this->mergePackageLinks('provide', $root); |
|
| 172 | 99 | $this->mergeSuggests($root); |
|
| 173 | 99 | $this->mergeExtra($root, $state); |
|
| 174 | 99 | $this->mergeScripts($root, $state); |
|
| 175 | |||
| 176 | 99 | $state->isDevMode() |
|
| 177 | 78 | ? $this->mergeDevInto($root, $state) |
|
| 178 | 21 | : $this->mergeReferences($root); |
|
| 179 | 99 | } |
|
| 180 | |||
| 181 | /* ------------------------------------------------------------------------------------------------ |
||
| 182 | | Other Functions |
||
| 183 | | ------------------------------------------------------------------------------------------------ |
||
| 184 | */ |
||
| 185 | /** |
||
| 186 | * Update Links with a 'self.version' constraint with the root package's version. |
||
| 187 | * |
||
| 188 | * @param string $type |
||
| 189 | * @param array $links |
||
| 190 | * @param \Composer\Package\RootPackageInterface $root |
||
| 191 | * |
||
| 192 | * @return array |
||
| 193 | */ |
||
| 194 | 63 | protected function replaceSelfVersionDependencies( |
|
| 195 | $type, array $links, RootPackageInterface $root |
||
| 196 | ) { |
||
| 197 | 63 | $linkType = BasePackage::$supportedLinkTypes[$type]; |
|
| 198 | 63 | $version = $root->getVersion(); |
|
| 199 | 63 | $prettyVersion = $root->getPrettyVersion(); |
|
| 200 | 63 | $vp = $this->versionParser; |
|
| 201 | 63 | $packages = $root->{'get'.ucfirst($linkType['method'])}(); |
|
| 202 | |||
| 203 | return array_map(function (Link $link) use ($linkType, $version, $prettyVersion, $vp, $packages) { |
||
| 204 | 63 | if ($link->getPrettyConstraint() !== 'self.version') { |
|
| 205 | 63 | return $link; |
|
| 206 | } |
||
| 207 | |||
| 208 | 9 | if (isset($packages[$link->getSource()])) { |
|
| 209 | /** @var \Composer\Package\Link $package */ |
||
| 210 | 6 | $package = $packages[$link->getSource()]; |
|
| 211 | 6 | $version = $package->getConstraint()->getPrettyString(); |
|
|
0 ignored issues
–
show
|
|||
| 212 | 6 | $prettyVersion = $package->getPrettyConstraint(); |
|
|
0 ignored issues
–
show
Consider using a different name than the imported variable
$prettyVersion, or did you forget to import by reference?
It seems like you are assigning to a variable which was imported through a For clarity, we suggest to use a different name or import by reference depending on whether you would like to have the change visibile in outer-scope. Change not visible in outer-scope$x = 1;
$callable = function() use ($x) {
$x = 2; // Not visible in outer scope. If you would like this, how
// about using a different variable name than $x?
};
$callable();
var_dump($x); // integer(1)
Change visible in outer-scope$x = 1;
$callable = function() use (&$x) {
$x = 2;
};
$callable();
var_dump($x); // integer(2)
Loading history...
|
|||
| 213 | } |
||
| 214 | |||
| 215 | 9 | return new Link( |
|
| 216 | 9 | $link->getSource(), |
|
| 217 | 9 | $link->getTarget(), |
|
| 218 | 9 | $vp->parseConstraints($version), |
|
| 219 | 9 | $linkType['description'], |
|
| 220 | 6 | $prettyVersion |
|
| 221 | ); |
||
| 222 | 63 | }, $links); |
|
| 223 | } |
||
| 224 | |||
| 225 | /** |
||
| 226 | * Get a full featured Package from a RootPackageInterface. |
||
| 227 | * |
||
| 228 | * @param \Composer\Package\RootPackageInterface|\Composer\Package\RootPackage $root |
||
| 229 | * @param string $method |
||
| 230 | * |
||
| 231 | * @return \Composer\Package\RootPackageInterface|\Composer\Package\RootPackage |
||
| 232 | */ |
||
| 233 | 99 | protected static function unwrapIfNeeded( |
|
| 234 | RootPackageInterface $root, $method = 'setExtra' |
||
| 235 | ) { |
||
| 236 | 99 | return ($root instanceof RootAliasPackage && ! method_exists($root, $method)) |
|
| 237 | 6 | ? $root->getAliasOf() |
|
| 238 | 99 | : $root; |
|
| 239 | } |
||
| 240 | } |
||
| 241 |
It seems like you are assigning to a variable which was imported through a
usestatement which was not imported by reference.For clarity, we suggest to use a different name or import by reference depending on whether you would like to have the change visibile in outer-scope.
Change not visible in outer-scope
Change visible in outer-scope