MediaWiki master
LockFileChecker.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\Composer;
22
23use Composer\Semver\Semver;
24use Status;
27
34 private $composerJson;
35
37 private $composerLock;
38
43 public function __construct( ComposerJson $composerJson, ComposerLock $composerLock ) {
44 $this->composerJson = $composerJson;
45 $this->composerLock = $composerLock;
46 }
47
54 public function check(): Status {
55 $status = Status::newGood();
56 $requiredButOld = [];
57 $requiredButMissing = [];
58
59 $installed = $this->composerLock->getInstalledDependencies();
60 foreach ( $this->composerJson->getRequiredDependencies() as $name => $version ) {
61 // Not installed at all.
62 if ( !isset( $installed[$name] ) ) {
63 $requiredButMissing[] = [
64 'name' => $name,
65 'wantedVersion' => $version
66 ];
67 continue;
68 }
69
70 // Installed; need to check it's the right version
71 if ( !SemVer::satisfies( $installed[$name]['version'], $version ) ) {
72 $requiredButOld[] = [
73 'name' => $name,
74 'wantedVersion' => $version,
75 'suppliedVersion' => $installed[$name]['version']
76 ];
77 }
78
79 // We're happy; loop to the next dependency.
80 }
81
82 if ( count( $requiredButOld ) === 0 && count( $requiredButMissing ) === 0 ) {
83 // We couldn't find any out-of-date or missing dependencies, so assume everything is ok!
84 return $status;
85 }
86
87 foreach ( $requiredButOld as [
88 "name" => $name,
89 "suppliedVersion" => $suppliedVersion,
90 "wantedVersion" => $wantedVersion
91 ] ) {
92 $status->error( 'composer-deps-outdated', $name, $suppliedVersion, $wantedVersion );
93 }
94
95 foreach ( $requiredButMissing as [
96 "name" => $name,
97 "wantedVersion" => $wantedVersion
98 ] ) {
99 $status->error( 'composer-deps-notinstalled', $name, $wantedVersion );
100 }
101
102 return $status;
103 }
104}
Used to check whether composer-installed dependencies (no-dev) are up-to-date.
__construct(ComposerJson $composerJson, ComposerLock $composerLock)
check()
This method will return a Status instance, you can use Status::isGood() to simply determine that the ...
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition Status.php:54
error( $message,... $parameters)
Add an error, do not set fatal flag This can be used for non-fatal errors.
Reads a composer.json file and provides accessors to get its hash and the required dependencies.
Reads a composer.lock file and provides accessors to get its hash and what is installed.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...