Completed
Push — develop ( 0e25c3...d044f3 )
by Zack
16:03
created
vendor/wp-cli/entity-command/src/User_Application_Password_Command.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
 		}
148 148
 
149 149
 		if ( empty( $application_passwords ) ) {
150
-			$application_passwords = [];
150
+			$application_passwords = [ ];
151 151
 		}
152 152
 
153 153
 		$order   = Utils\get_flag_value( $assoc_args, 'order' );
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
 
156 156
 		usort(
157 157
 			$application_passwords,
158
-			static function ( $a, $b ) use ( $orderby, $order ) {
158
+			static function( $a, $b ) use ( $orderby, $order ) {
159 159
 				// Sort array.
160 160
 				return 'asc' === $order
161 161
 					? $a[ $orderby ] > $b[ $orderby ]
@@ -183,14 +183,14 @@  discard block
 block discarded – undo
183 183
 
184 184
 			$application_passwords = array_filter(
185 185
 				$application_passwords,
186
-				static function ( $application_password ) use ( $field, $value ) {
186
+				static function( $application_password ) use ( $field, $value ) {
187 187
 					return $application_password[ $field ] === $value;
188 188
 				}
189 189
 			);
190 190
 		}
191 191
 
192
-		if ( ! empty( $assoc_args['fields'] ) ) {
193
-			$fields = explode( ',', $assoc_args['fields'] );
192
+		if ( ! empty( $assoc_args[ 'fields' ] ) ) {
193
+			$fields = explode( ',', $assoc_args[ 'fields' ] );
194 194
 		}
195 195
 
196 196
 		$formatter = new Formatter( $assoc_args, $fields );
@@ -256,8 +256,8 @@  discard block
 block discarded – undo
256 256
 
257 257
 		$fields = self::APPLICATION_PASSWORD_FIELDS;
258 258
 
259
-		if ( ! empty( $assoc_args['fields'] ) ) {
260
-			$fields = explode( ',', $assoc_args['fields'] );
259
+		if ( ! empty( $assoc_args[ 'fields' ] ) ) {
260
+			$fields = explode( ',', $assoc_args[ 'fields' ] );
261 261
 		}
262 262
 
263 263
 		$formatter = new Formatter( $assoc_args, $fields );
@@ -319,12 +319,12 @@  discard block
 block discarded – undo
319 319
 		}
320 320
 
321 321
 		if ( Utils\get_flag_value( $assoc_args, 'porcelain', false ) ) {
322
-			WP_CLI::line( $result[0] );
322
+			WP_CLI::line( $result[ 0 ] );
323 323
 			WP_CLI::halt( 0 );
324 324
 		}
325 325
 
326 326
 		WP_CLI::success( 'Created application password.' );
327
-		WP_CLI::line( "Password: {$result[0]}" );
327
+		WP_CLI::line( "Password: {$result[ 0 ]}" );
328 328
 	}
329 329
 
330 330
 	/**
@@ -519,8 +519,8 @@  discard block
 block discarded – undo
519 519
 	 * @throws ExitException If the user is not found.
520 520
 	 */
521 521
 	private function replace_login_with_user_id( $args ) {
522
-		$user    = ( new UserFetcher() )->get_check( $args[0] );
523
-		$args[0] = $user->ID;
522
+		$user    = ( new UserFetcher() )->get_check( $args[ 0 ] );
523
+		$args[ 0 ] = $user->ID;
524 524
 
525 525
 		return $args;
526 526
 	}
@@ -540,7 +540,7 @@  discard block
 block discarded – undo
540 540
 			$passwords = WP_Application_Passwords::get_user_application_passwords( $user_id );
541 541
 
542 542
 			foreach ( $passwords as $password ) {
543
-				if ( strtolower( $password['name'] ) === strtolower( $name ) ) {
543
+				if ( strtolower( $password[ 'name' ] ) === strtolower( $name ) ) {
544 544
 					return true;
545 545
 				}
546 546
 			}
Please login to merge, or discard this patch.
vendor/phpdocumentor/type-resolver/src/PseudoTypes/NegativeInteger.php 2 patches
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -24,16 +24,16 @@
 block discarded – undo
24 24
  */
25 25
 final class NegativeInteger extends Integer implements PseudoType
26 26
 {
27
-    public function underlyingType(): Type
28
-    {
29
-        return new Integer();
30
-    }
27
+	public function underlyingType(): Type
28
+	{
29
+		return new Integer();
30
+	}
31 31
 
32
-    /**
33
-     * Returns a rendered output of the Type as it would be used in a DocBlock.
34
-     */
35
-    public function __toString(): string
36
-    {
37
-        return 'negative-int';
38
-    }
32
+	/**
33
+	 * Returns a rendered output of the Type as it would be used in a DocBlock.
34
+	 */
35
+	public function __toString(): string
36
+	{
37
+		return 'negative-int';
38
+	}
39 39
 }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -22,8 +22,7 @@
 block discarded – undo
22 22
  *
23 23
  * @psalm-immutable
24 24
  */
25
-final class NegativeInteger extends Integer implements PseudoType
26
-{
25
+final class NegativeInteger extends Integer implements PseudoType {
27 26
     public function underlyingType(): Type
28 27
     {
29 28
         return new Integer();
Please login to merge, or discard this patch.
vendor/phpdocumentor/type-resolver/src/PseudoTypes/Numeric_.php 3 patches
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -27,21 +27,21 @@
 block discarded – undo
27 27
  */
28 28
 final class Numeric_ extends AggregatedType implements PseudoType
29 29
 {
30
-    public function __construct()
31
-    {
32
-        AggregatedType::__construct([new NumericString(), new Integer(), new Float_()], '|');
33
-    }
30
+	public function __construct()
31
+	{
32
+		AggregatedType::__construct([new NumericString(), new Integer(), new Float_()], '|');
33
+	}
34 34
 
35
-    public function underlyingType(): Type
36
-    {
37
-        return new Compound([new NumericString(), new Integer(), new Float_()]);
38
-    }
35
+	public function underlyingType(): Type
36
+	{
37
+		return new Compound([new NumericString(), new Integer(), new Float_()]);
38
+	}
39 39
 
40
-    /**
41
-     * Returns a rendered output of the Type as it would be used in a DocBlock.
42
-     */
43
-    public function __toString(): string
44
-    {
45
-        return 'numeric';
46
-    }
40
+	/**
41
+	 * Returns a rendered output of the Type as it would be used in a DocBlock.
42
+	 */
43
+	public function __toString(): string
44
+	{
45
+		return 'numeric';
46
+	}
47 47
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -29,12 +29,12 @@
 block discarded – undo
29 29
 {
30 30
     public function __construct()
31 31
     {
32
-        AggregatedType::__construct([new NumericString(), new Integer(), new Float_()], '|');
32
+        AggregatedType::__construct( [ new NumericString(), new Integer(), new Float_() ], '|' );
33 33
     }
34 34
 
35 35
     public function underlyingType(): Type
36 36
     {
37
-        return new Compound([new NumericString(), new Integer(), new Float_()]);
37
+        return new Compound( [ new NumericString(), new Integer(), new Float_() ] );
38 38
     }
39 39
 
40 40
     /**
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -25,10 +25,8 @@
 block discarded – undo
25 25
  *
26 26
  * @psalm-immutable
27 27
  */
28
-final class Numeric_ extends AggregatedType implements PseudoType
29
-{
30
-    public function __construct()
31
-    {
28
+final class Numeric_ extends AggregatedType implements PseudoType {
29
+    public function __construct() {
32 30
         AggregatedType::__construct([new NumericString(), new Integer(), new Float_()], '|');
33 31
     }
34 32
 
Please login to merge, or discard this patch.
vendor/phpdocumentor/type-resolver/src/PseudoTypes/IntegerRange.php 3 patches
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -24,38 +24,38 @@
 block discarded – undo
24 24
  */
25 25
 final class IntegerRange extends Integer implements PseudoType
26 26
 {
27
-    /** @var string */
28
-    private $minValue;
29
-
30
-    /** @var string */
31
-    private $maxValue;
32
-
33
-    public function __construct(string $minValue, string $maxValue)
34
-    {
35
-        $this->minValue = $minValue;
36
-        $this->maxValue = $maxValue;
37
-    }
38
-
39
-    public function underlyingType(): Type
40
-    {
41
-        return new Integer();
42
-    }
43
-
44
-    public function getMinValue(): string
45
-    {
46
-        return $this->minValue;
47
-    }
48
-
49
-    public function getMaxValue(): string
50
-    {
51
-        return $this->maxValue;
52
-    }
53
-
54
-    /**
55
-     * Returns a rendered output of the Type as it would be used in a DocBlock.
56
-     */
57
-    public function __toString(): string
58
-    {
59
-        return 'int<' . $this->minValue . ', ' . $this->maxValue . '>';
60
-    }
27
+	/** @var string */
28
+	private $minValue;
29
+
30
+	/** @var string */
31
+	private $maxValue;
32
+
33
+	public function __construct(string $minValue, string $maxValue)
34
+	{
35
+		$this->minValue = $minValue;
36
+		$this->maxValue = $maxValue;
37
+	}
38
+
39
+	public function underlyingType(): Type
40
+	{
41
+		return new Integer();
42
+	}
43
+
44
+	public function getMinValue(): string
45
+	{
46
+		return $this->minValue;
47
+	}
48
+
49
+	public function getMaxValue(): string
50
+	{
51
+		return $this->maxValue;
52
+	}
53
+
54
+	/**
55
+	 * Returns a rendered output of the Type as it would be used in a DocBlock.
56
+	 */
57
+	public function __toString(): string
58
+	{
59
+		return 'int<' . $this->minValue . ', ' . $this->maxValue . '>';
60
+	}
61 61
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@
 block discarded – undo
30 30
     /** @var string */
31 31
     private $maxValue;
32 32
 
33
-    public function __construct(string $minValue, string $maxValue)
33
+    public function __construct( string $minValue, string $maxValue )
34 34
     {
35 35
         $this->minValue = $minValue;
36 36
         $this->maxValue = $maxValue;
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -22,16 +22,14 @@
 block discarded – undo
22 22
  *
23 23
  * @psalm-immutable
24 24
  */
25
-final class IntegerRange extends Integer implements PseudoType
26
-{
25
+final class IntegerRange extends Integer implements PseudoType {
27 26
     /** @var string */
28 27
     private $minValue;
29 28
 
30 29
     /** @var string */
31 30
     private $maxValue;
32 31
 
33
-    public function __construct(string $minValue, string $maxValue)
34
-    {
32
+    public function __construct(string $minValue, string $maxValue) {
35 33
         $this->minValue = $minValue;
36 34
         $this->maxValue = $maxValue;
37 35
     }
Please login to merge, or discard this patch.
vendor/phpdocumentor/type-resolver/src/PseudoTypes/List_.php 3 patches
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -26,25 +26,25 @@
 block discarded – undo
26 26
  */
27 27
 final class List_ extends Array_ implements PseudoType
28 28
 {
29
-    public function underlyingType(): Type
30
-    {
31
-        return new Array_();
32
-    }
33
-
34
-    public function __construct(?Type $valueType = null)
35
-    {
36
-        parent::__construct($valueType, new Integer());
37
-    }
38
-
39
-    /**
40
-     * Returns a rendered output of the Type as it would be used in a DocBlock.
41
-     */
42
-    public function __toString(): string
43
-    {
44
-        if ($this->valueType instanceof Mixed_) {
45
-            return 'list';
46
-        }
47
-
48
-        return 'list<' . $this->valueType . '>';
49
-    }
29
+	public function underlyingType(): Type
30
+	{
31
+		return new Array_();
32
+	}
33
+
34
+	public function __construct(?Type $valueType = null)
35
+	{
36
+		parent::__construct($valueType, new Integer());
37
+	}
38
+
39
+	/**
40
+	 * Returns a rendered output of the Type as it would be used in a DocBlock.
41
+	 */
42
+	public function __toString(): string
43
+	{
44
+		if ($this->valueType instanceof Mixed_) {
45
+			return 'list';
46
+		}
47
+
48
+		return 'list<' . $this->valueType . '>';
49
+	}
50 50
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -31,9 +31,9 @@  discard block
 block discarded – undo
31 31
         return new Array_();
32 32
     }
33 33
 
34
-    public function __construct(?Type $valueType = null)
34
+    public function __construct( ?Type $valueType = null )
35 35
     {
36
-        parent::__construct($valueType, new Integer());
36
+        parent::__construct( $valueType, new Integer() );
37 37
     }
38 38
 
39 39
     /**
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
      */
42 42
     public function __toString(): string
43 43
     {
44
-        if ($this->valueType instanceof Mixed_) {
44
+        if ( $this->valueType instanceof Mixed_ ) {
45 45
             return 'list';
46 46
         }
47 47
 
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -24,15 +24,13 @@
 block discarded – undo
24 24
  *
25 25
  * @psalm-immutable
26 26
  */
27
-final class List_ extends Array_ implements PseudoType
28
-{
27
+final class List_ extends Array_ implements PseudoType {
29 28
     public function underlyingType(): Type
30 29
     {
31 30
         return new Array_();
32 31
     }
33 32
 
34
-    public function __construct(?Type $valueType = null)
35
-    {
33
+    public function __construct(?Type $valueType = null) {
36 34
         parent::__construct($valueType, new Integer());
37 35
     }
38 36
 
Please login to merge, or discard this patch.
vendor/doctrine/inflector/lib/Doctrine/Common/Inflector/Inflector.php 3 patches
Indentation   +209 added lines, -209 removed lines patch added patch discarded remove patch
@@ -44,241 +44,241 @@
 block discarded – undo
44 44
  */
45 45
 class Inflector
46 46
 {
47
-    /**
48
-     * @var LanguageInflectorFactory|null
49
-     */
50
-    private static $factory;
47
+	/**
48
+	 * @var LanguageInflectorFactory|null
49
+	 */
50
+	private static $factory;
51 51
 
52
-    /** @var InflectorObject|null */
53
-    private static $instance;
52
+	/** @var InflectorObject|null */
53
+	private static $instance;
54 54
 
55
-    private static function getInstance() : InflectorObject
56
-    {
57
-        if (self::$factory === null) {
58
-            self::$factory = self::createFactory();
59
-        }
55
+	private static function getInstance() : InflectorObject
56
+	{
57
+		if (self::$factory === null) {
58
+			self::$factory = self::createFactory();
59
+		}
60 60
 
61
-        if (self::$instance === null) {
62
-            self::$instance = self::$factory->build();
63
-        }
61
+		if (self::$instance === null) {
62
+			self::$instance = self::$factory->build();
63
+		}
64 64
 
65
-        return self::$instance;
66
-    }
65
+		return self::$instance;
66
+	}
67 67
 
68
-    private static function createFactory() : LanguageInflectorFactory
69
-    {
70
-        return InflectorFactory::create();
71
-    }
68
+	private static function createFactory() : LanguageInflectorFactory
69
+	{
70
+		return InflectorFactory::create();
71
+	}
72 72
 
73
-    /**
74
-     * Converts a word into the format for a Doctrine table name. Converts 'ModelName' to 'model_name'.
75
-     *
76
-     * @deprecated
77
-     */
78
-    public static function tableize(string $word) : string
79
-    {
80
-        @trigger_error(sprintf('The "%s" method is deprecated and will be dropped in doctrine/inflector 2.0. Please update to the new Inflector API.', __METHOD__), E_USER_DEPRECATED);
73
+	/**
74
+	 * Converts a word into the format for a Doctrine table name. Converts 'ModelName' to 'model_name'.
75
+	 *
76
+	 * @deprecated
77
+	 */
78
+	public static function tableize(string $word) : string
79
+	{
80
+		@trigger_error(sprintf('The "%s" method is deprecated and will be dropped in doctrine/inflector 2.0. Please update to the new Inflector API.', __METHOD__), E_USER_DEPRECATED);
81 81
 
82
-        return self::getInstance()->tableize($word);
83
-    }
82
+		return self::getInstance()->tableize($word);
83
+	}
84 84
 
85
-    /**
86
-     * Converts a word into the format for a Doctrine class name. Converts 'table_name' to 'TableName'.
87
-     */
88
-    public static function classify(string $word) : string
89
-    {
90
-        @trigger_error(sprintf('The "%s" method is deprecated and will be dropped in doctrine/inflector 2.0. Please update to the new Inflector API.', __METHOD__), E_USER_DEPRECATED);
85
+	/**
86
+	 * Converts a word into the format for a Doctrine class name. Converts 'table_name' to 'TableName'.
87
+	 */
88
+	public static function classify(string $word) : string
89
+	{
90
+		@trigger_error(sprintf('The "%s" method is deprecated and will be dropped in doctrine/inflector 2.0. Please update to the new Inflector API.', __METHOD__), E_USER_DEPRECATED);
91 91
 
92
-        return self::getInstance()->classify($word);
93
-    }
92
+		return self::getInstance()->classify($word);
93
+	}
94 94
 
95
-    /**
96
-     * Camelizes a word. This uses the classify() method and turns the first character to lowercase.
97
-     *
98
-     * @deprecated
99
-     */
100
-    public static function camelize(string $word) : string
101
-    {
102
-        @trigger_error(sprintf('The "%s" method is deprecated and will be dropped in doctrine/inflector 2.0. Please update to the new Inflector API.', __METHOD__), E_USER_DEPRECATED);
95
+	/**
96
+	 * Camelizes a word. This uses the classify() method and turns the first character to lowercase.
97
+	 *
98
+	 * @deprecated
99
+	 */
100
+	public static function camelize(string $word) : string
101
+	{
102
+		@trigger_error(sprintf('The "%s" method is deprecated and will be dropped in doctrine/inflector 2.0. Please update to the new Inflector API.', __METHOD__), E_USER_DEPRECATED);
103 103
 
104
-        return self::getInstance()->camelize($word);
105
-    }
104
+		return self::getInstance()->camelize($word);
105
+	}
106 106
 
107
-    /**
108
-     * Uppercases words with configurable delimiters between words.
109
-     *
110
-     * Takes a string and capitalizes all of the words, like PHP's built-in
111
-     * ucwords function. This extends that behavior, however, by allowing the
112
-     * word delimiters to be configured, rather than only separating on
113
-     * whitespace.
114
-     *
115
-     * Here is an example:
116
-     * <code>
117
-     * <?php
118
-     * $string = 'top-o-the-morning to all_of_you!';
119
-     * echo \Doctrine\Common\Inflector\Inflector::ucwords($string);
120
-     * // Top-O-The-Morning To All_of_you!
121
-     *
122
-     * echo \Doctrine\Common\Inflector\Inflector::ucwords($string, '-_ ');
123
-     * // Top-O-The-Morning To All_Of_You!
124
-     * ?>
125
-     * </code>
126
-     *
127
-     * @param string $string The string to operate on.
128
-     * @param string $delimiters A list of word separators.
129
-     *
130
-     * @return string The string with all delimiter-separated words capitalized.
131
-     *
132
-     * @deprecated
133
-     */
134
-    public static function ucwords(string $string, string $delimiters = " \n\t\r\0\x0B-") : string
135
-    {
136
-        @trigger_error(sprintf('The "%s" method is deprecated and will be dropped in doctrine/inflector 2.0. Please use the "ucwords" function instead.', __METHOD__), E_USER_DEPRECATED);
107
+	/**
108
+	 * Uppercases words with configurable delimiters between words.
109
+	 *
110
+	 * Takes a string and capitalizes all of the words, like PHP's built-in
111
+	 * ucwords function. This extends that behavior, however, by allowing the
112
+	 * word delimiters to be configured, rather than only separating on
113
+	 * whitespace.
114
+	 *
115
+	 * Here is an example:
116
+	 * <code>
117
+	 * <?php
118
+	 * $string = 'top-o-the-morning to all_of_you!';
119
+	 * echo \Doctrine\Common\Inflector\Inflector::ucwords($string);
120
+	 * // Top-O-The-Morning To All_of_you!
121
+	 *
122
+	 * echo \Doctrine\Common\Inflector\Inflector::ucwords($string, '-_ ');
123
+	 * // Top-O-The-Morning To All_Of_You!
124
+	 * ?>
125
+	 * </code>
126
+	 *
127
+	 * @param string $string The string to operate on.
128
+	 * @param string $delimiters A list of word separators.
129
+	 *
130
+	 * @return string The string with all delimiter-separated words capitalized.
131
+	 *
132
+	 * @deprecated
133
+	 */
134
+	public static function ucwords(string $string, string $delimiters = " \n\t\r\0\x0B-") : string
135
+	{
136
+		@trigger_error(sprintf('The "%s" method is deprecated and will be dropped in doctrine/inflector 2.0. Please use the "ucwords" function instead.', __METHOD__), E_USER_DEPRECATED);
137 137
 
138
-        return ucwords($string, $delimiters);
139
-    }
138
+		return ucwords($string, $delimiters);
139
+	}
140 140
 
141
-    /**
142
-     * Clears Inflectors inflected value caches, and resets the inflection
143
-     * rules to the initial values.
144
-     *
145
-     * @deprecated
146
-     */
147
-    public static function reset() : void
148
-    {
149
-        @trigger_error(sprintf('The "%s" method is deprecated and will be dropped in doctrine/inflector 2.0. Please update to the new Inflector API.', __METHOD__), E_USER_DEPRECATED);
141
+	/**
142
+	 * Clears Inflectors inflected value caches, and resets the inflection
143
+	 * rules to the initial values.
144
+	 *
145
+	 * @deprecated
146
+	 */
147
+	public static function reset() : void
148
+	{
149
+		@trigger_error(sprintf('The "%s" method is deprecated and will be dropped in doctrine/inflector 2.0. Please update to the new Inflector API.', __METHOD__), E_USER_DEPRECATED);
150 150
 
151
-        self::$factory = null;
152
-        self::$instance = null;
153
-    }
151
+		self::$factory = null;
152
+		self::$instance = null;
153
+	}
154 154
 
155
-    /**
156
-     * Adds custom inflection $rules, of either 'plural' or 'singular' $type.
157
-     *
158
-     * ### Usage:
159
-     *
160
-     * {{{
161
-     * Inflector::rules('plural', array('/^(inflect)or$/i' => '\1ables'));
162
-     * Inflector::rules('plural', array(
163
-     *     'rules' => array('/^(inflect)ors$/i' => '\1ables'),
164
-     *     'uninflected' => array('dontinflectme'),
165
-     *     'irregular' => array('red' => 'redlings')
166
-     * ));
167
-     * }}}
168
-     *
169
-     * @param string  $type         The type of inflection, either 'plural' or 'singular'
170
-     * @param array<string,mixed>|iterable<string,mixed> $rules An array of rules to be added.
171
-     * @param boolean $reset        If true, will unset default inflections for all
172
-     *                              new rules that are being defined in $rules.
173
-     *
174
-     * @return void
175
-     *
176
-     * @deprecated
177
-     */
178
-    public static function rules(string $type, iterable $rules, bool $reset = false) : void
179
-    {
180
-        @trigger_error(sprintf('The "%s" method is deprecated and will be dropped in doctrine/inflector 2.0. Please update to the new Inflector API.', __METHOD__), E_USER_DEPRECATED);
155
+	/**
156
+	 * Adds custom inflection $rules, of either 'plural' or 'singular' $type.
157
+	 *
158
+	 * ### Usage:
159
+	 *
160
+	 * {{{
161
+	 * Inflector::rules('plural', array('/^(inflect)or$/i' => '\1ables'));
162
+	 * Inflector::rules('plural', array(
163
+	 *     'rules' => array('/^(inflect)ors$/i' => '\1ables'),
164
+	 *     'uninflected' => array('dontinflectme'),
165
+	 *     'irregular' => array('red' => 'redlings')
166
+	 * ));
167
+	 * }}}
168
+	 *
169
+	 * @param string  $type         The type of inflection, either 'plural' or 'singular'
170
+	 * @param array<string,mixed>|iterable<string,mixed> $rules An array of rules to be added.
171
+	 * @param boolean $reset        If true, will unset default inflections for all
172
+	 *                              new rules that are being defined in $rules.
173
+	 *
174
+	 * @return void
175
+	 *
176
+	 * @deprecated
177
+	 */
178
+	public static function rules(string $type, iterable $rules, bool $reset = false) : void
179
+	{
180
+		@trigger_error(sprintf('The "%s" method is deprecated and will be dropped in doctrine/inflector 2.0. Please update to the new Inflector API.', __METHOD__), E_USER_DEPRECATED);
181 181
 
182
-        if (self::$factory === null) {
183
-            self::$factory = self::createFactory();
184
-        }
182
+		if (self::$factory === null) {
183
+			self::$factory = self::createFactory();
184
+		}
185 185
 
186
-        self::$instance = null;
186
+		self::$instance = null;
187 187
 
188
-        switch ($type) {
189
-            case 'singular':
190
-                self::$factory->withSingularRules(self::buildRuleset($rules), $reset);
191
-                break;
192
-            case 'plural':
193
-                self::$factory->withPluralRules(self::buildRuleset($rules), $reset);
194
-                break;
195
-            default:
196
-                throw new InvalidArgumentException(sprintf('Cannot define custom inflection rules for type "%s".', $type));
197
-        }
198
-    }
188
+		switch ($type) {
189
+			case 'singular':
190
+				self::$factory->withSingularRules(self::buildRuleset($rules), $reset);
191
+				break;
192
+			case 'plural':
193
+				self::$factory->withPluralRules(self::buildRuleset($rules), $reset);
194
+				break;
195
+			default:
196
+				throw new InvalidArgumentException(sprintf('Cannot define custom inflection rules for type "%s".', $type));
197
+		}
198
+	}
199 199
 
200
-    /**
201
-      * @param array<string,mixed>|iterable<string,mixed> $rules An array of rules to be added.
202
-      */
203
-    private static function buildRuleset(iterable $rules) : Ruleset
204
-    {
205
-        $regular = [];
206
-        $irregular = [];
207
-        $uninflected = [];
200
+	/**
201
+	 * @param array<string,mixed>|iterable<string,mixed> $rules An array of rules to be added.
202
+	 */
203
+	private static function buildRuleset(iterable $rules) : Ruleset
204
+	{
205
+		$regular = [];
206
+		$irregular = [];
207
+		$uninflected = [];
208 208
 
209
-        foreach ($rules as $rule => $pattern) {
210
-            if ( ! is_array($pattern)) {
211
-                $regular[$rule] = $pattern;
209
+		foreach ($rules as $rule => $pattern) {
210
+			if ( ! is_array($pattern)) {
211
+				$regular[$rule] = $pattern;
212 212
 
213
-                continue;
214
-            }
213
+				continue;
214
+			}
215 215
 
216
-            switch ($rule) {
217
-                case 'uninflected':
218
-                    $uninflected = $pattern;
219
-                    break;
220
-                case 'irregular':
221
-                    $irregular = $pattern;
222
-                    break;
223
-                case 'rules':
224
-                    $regular = $pattern;
225
-                    break;
226
-            }
227
-        }
216
+			switch ($rule) {
217
+				case 'uninflected':
218
+					$uninflected = $pattern;
219
+					break;
220
+				case 'irregular':
221
+					$irregular = $pattern;
222
+					break;
223
+				case 'rules':
224
+					$regular = $pattern;
225
+					break;
226
+			}
227
+		}
228 228
 
229
-        return new Ruleset(
230
-            new Transformations(...array_map(
231
-                static function (string $pattern, string $replacement) : Transformation {
232
-                    return new Transformation(new Pattern($pattern), $replacement);
233
-                },
234
-                array_keys($regular),
235
-                array_values($regular)
236
-            )),
237
-            new Patterns(...array_map(
238
-                static function (string $pattern) : Pattern {
239
-                    return new Pattern($pattern);
240
-                },
241
-                $uninflected
242
-            )),
243
-            new Substitutions(...array_map(
244
-                static function (string $word, string $to) : Substitution {
245
-                    return new Substitution(new Word($word), new Word($to));
246
-                },
247
-                array_keys($irregular),
248
-                array_values($irregular)
249
-            ))
250
-        );
251
-    }
229
+		return new Ruleset(
230
+			new Transformations(...array_map(
231
+				static function (string $pattern, string $replacement) : Transformation {
232
+					return new Transformation(new Pattern($pattern), $replacement);
233
+				},
234
+				array_keys($regular),
235
+				array_values($regular)
236
+			)),
237
+			new Patterns(...array_map(
238
+				static function (string $pattern) : Pattern {
239
+					return new Pattern($pattern);
240
+				},
241
+				$uninflected
242
+			)),
243
+			new Substitutions(...array_map(
244
+				static function (string $word, string $to) : Substitution {
245
+					return new Substitution(new Word($word), new Word($to));
246
+				},
247
+				array_keys($irregular),
248
+				array_values($irregular)
249
+			))
250
+		);
251
+	}
252 252
 
253
-    /**
254
-     * Returns a word in plural form.
255
-     *
256
-     * @param string $word The word in singular form.
257
-     *
258
-     * @return string The word in plural form.
259
-     *
260
-     * @deprecated
261
-     */
262
-    public static function pluralize(string $word) : string
263
-    {
264
-        @trigger_error(sprintf('The "%s" method is deprecated and will be dropped in doctrine/inflector 2.0. Please update to the new Inflector API.', __METHOD__), E_USER_DEPRECATED);
253
+	/**
254
+	 * Returns a word in plural form.
255
+	 *
256
+	 * @param string $word The word in singular form.
257
+	 *
258
+	 * @return string The word in plural form.
259
+	 *
260
+	 * @deprecated
261
+	 */
262
+	public static function pluralize(string $word) : string
263
+	{
264
+		@trigger_error(sprintf('The "%s" method is deprecated and will be dropped in doctrine/inflector 2.0. Please update to the new Inflector API.', __METHOD__), E_USER_DEPRECATED);
265 265
 
266
-        return self::getInstance()->pluralize($word);
267
-    }
266
+		return self::getInstance()->pluralize($word);
267
+	}
268 268
 
269
-    /**
270
-     * Returns a word in singular form.
271
-     *
272
-     * @param string $word The word in plural form.
273
-     *
274
-     * @return string The word in singular form.
275
-     *
276
-     * @deprecated
277
-     */
278
-    public static function singularize(string $word) : string
279
-    {
280
-        @trigger_error(sprintf('The "%s" method is deprecated and will be dropped in doctrine/inflector 2.0. Please update to the new Inflector API.', __METHOD__), E_USER_DEPRECATED);
269
+	/**
270
+	 * Returns a word in singular form.
271
+	 *
272
+	 * @param string $word The word in plural form.
273
+	 *
274
+	 * @return string The word in singular form.
275
+	 *
276
+	 * @deprecated
277
+	 */
278
+	public static function singularize(string $word) : string
279
+	{
280
+		@trigger_error(sprintf('The "%s" method is deprecated and will be dropped in doctrine/inflector 2.0. Please update to the new Inflector API.', __METHOD__), E_USER_DEPRECATED);
281 281
 
282
-        return self::getInstance()->singularize($word);
283
-    }
282
+		return self::getInstance()->singularize($word);
283
+	}
284 284
 }
Please login to merge, or discard this patch.
Spacing   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -54,11 +54,11 @@  discard block
 block discarded – undo
54 54
 
55 55
     private static function getInstance() : InflectorObject
56 56
     {
57
-        if (self::$factory === null) {
57
+        if ( self::$factory === null ) {
58 58
             self::$factory = self::createFactory();
59 59
         }
60 60
 
61
-        if (self::$instance === null) {
61
+        if ( self::$instance === null ) {
62 62
             self::$instance = self::$factory->build();
63 63
         }
64 64
 
@@ -75,21 +75,21 @@  discard block
 block discarded – undo
75 75
      *
76 76
      * @deprecated
77 77
      */
78
-    public static function tableize(string $word) : string
78
+    public static function tableize( string $word ) : string
79 79
     {
80
-        @trigger_error(sprintf('The "%s" method is deprecated and will be dropped in doctrine/inflector 2.0. Please update to the new Inflector API.', __METHOD__), E_USER_DEPRECATED);
80
+        @trigger_error( sprintf( 'The "%s" method is deprecated and will be dropped in doctrine/inflector 2.0. Please update to the new Inflector API.', __METHOD__ ), E_USER_DEPRECATED );
81 81
 
82
-        return self::getInstance()->tableize($word);
82
+        return self::getInstance()->tableize( $word );
83 83
     }
84 84
 
85 85
     /**
86 86
      * Converts a word into the format for a Doctrine class name. Converts 'table_name' to 'TableName'.
87 87
      */
88
-    public static function classify(string $word) : string
88
+    public static function classify( string $word ) : string
89 89
     {
90
-        @trigger_error(sprintf('The "%s" method is deprecated and will be dropped in doctrine/inflector 2.0. Please update to the new Inflector API.', __METHOD__), E_USER_DEPRECATED);
90
+        @trigger_error( sprintf( 'The "%s" method is deprecated and will be dropped in doctrine/inflector 2.0. Please update to the new Inflector API.', __METHOD__ ), E_USER_DEPRECATED );
91 91
 
92
-        return self::getInstance()->classify($word);
92
+        return self::getInstance()->classify( $word );
93 93
     }
94 94
 
95 95
     /**
@@ -97,11 +97,11 @@  discard block
 block discarded – undo
97 97
      *
98 98
      * @deprecated
99 99
      */
100
-    public static function camelize(string $word) : string
100
+    public static function camelize( string $word ) : string
101 101
     {
102
-        @trigger_error(sprintf('The "%s" method is deprecated and will be dropped in doctrine/inflector 2.0. Please update to the new Inflector API.', __METHOD__), E_USER_DEPRECATED);
102
+        @trigger_error( sprintf( 'The "%s" method is deprecated and will be dropped in doctrine/inflector 2.0. Please update to the new Inflector API.', __METHOD__ ), E_USER_DEPRECATED );
103 103
 
104
-        return self::getInstance()->camelize($word);
104
+        return self::getInstance()->camelize( $word );
105 105
     }
106 106
 
107 107
     /**
@@ -131,11 +131,11 @@  discard block
 block discarded – undo
131 131
      *
132 132
      * @deprecated
133 133
      */
134
-    public static function ucwords(string $string, string $delimiters = " \n\t\r\0\x0B-") : string
134
+    public static function ucwords( string $string, string $delimiters = " \n\t\r\0\x0B-" ) : string
135 135
     {
136
-        @trigger_error(sprintf('The "%s" method is deprecated and will be dropped in doctrine/inflector 2.0. Please use the "ucwords" function instead.', __METHOD__), E_USER_DEPRECATED);
136
+        @trigger_error( sprintf( 'The "%s" method is deprecated and will be dropped in doctrine/inflector 2.0. Please use the "ucwords" function instead.', __METHOD__ ), E_USER_DEPRECATED );
137 137
 
138
-        return ucwords($string, $delimiters);
138
+        return ucwords( $string, $delimiters );
139 139
     }
140 140
 
141 141
     /**
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
      */
147 147
     public static function reset() : void
148 148
     {
149
-        @trigger_error(sprintf('The "%s" method is deprecated and will be dropped in doctrine/inflector 2.0. Please update to the new Inflector API.', __METHOD__), E_USER_DEPRECATED);
149
+        @trigger_error( sprintf( 'The "%s" method is deprecated and will be dropped in doctrine/inflector 2.0. Please update to the new Inflector API.', __METHOD__ ), E_USER_DEPRECATED );
150 150
 
151 151
         self::$factory = null;
152 152
         self::$instance = null;
@@ -175,45 +175,45 @@  discard block
 block discarded – undo
175 175
      *
176 176
      * @deprecated
177 177
      */
178
-    public static function rules(string $type, iterable $rules, bool $reset = false) : void
178
+    public static function rules( string $type, iterable $rules, bool $reset = false ) : void
179 179
     {
180
-        @trigger_error(sprintf('The "%s" method is deprecated and will be dropped in doctrine/inflector 2.0. Please update to the new Inflector API.', __METHOD__), E_USER_DEPRECATED);
180
+        @trigger_error( sprintf( 'The "%s" method is deprecated and will be dropped in doctrine/inflector 2.0. Please update to the new Inflector API.', __METHOD__ ), E_USER_DEPRECATED );
181 181
 
182
-        if (self::$factory === null) {
182
+        if ( self::$factory === null ) {
183 183
             self::$factory = self::createFactory();
184 184
         }
185 185
 
186 186
         self::$instance = null;
187 187
 
188
-        switch ($type) {
188
+        switch ( $type ) {
189 189
             case 'singular':
190
-                self::$factory->withSingularRules(self::buildRuleset($rules), $reset);
190
+                self::$factory->withSingularRules( self::buildRuleset( $rules ), $reset );
191 191
                 break;
192 192
             case 'plural':
193
-                self::$factory->withPluralRules(self::buildRuleset($rules), $reset);
193
+                self::$factory->withPluralRules( self::buildRuleset( $rules ), $reset );
194 194
                 break;
195 195
             default:
196
-                throw new InvalidArgumentException(sprintf('Cannot define custom inflection rules for type "%s".', $type));
196
+                throw new InvalidArgumentException( sprintf( 'Cannot define custom inflection rules for type "%s".', $type ) );
197 197
         }
198 198
     }
199 199
 
200 200
     /**
201 201
       * @param array<string,mixed>|iterable<string,mixed> $rules An array of rules to be added.
202 202
       */
203
-    private static function buildRuleset(iterable $rules) : Ruleset
203
+    private static function buildRuleset( iterable $rules ) : Ruleset
204 204
     {
205
-        $regular = [];
206
-        $irregular = [];
207
-        $uninflected = [];
205
+        $regular = [ ];
206
+        $irregular = [ ];
207
+        $uninflected = [ ];
208 208
 
209
-        foreach ($rules as $rule => $pattern) {
210
-            if ( ! is_array($pattern)) {
211
-                $regular[$rule] = $pattern;
209
+        foreach ( $rules as $rule => $pattern ) {
210
+            if ( ! is_array( $pattern ) ) {
211
+                $regular[ $rule ] = $pattern;
212 212
 
213 213
                 continue;
214 214
             }
215 215
 
216
-            switch ($rule) {
216
+            switch ( $rule ) {
217 217
                 case 'uninflected':
218 218
                     $uninflected = $pattern;
219 219
                     break;
@@ -227,26 +227,26 @@  discard block
 block discarded – undo
227 227
         }
228 228
 
229 229
         return new Ruleset(
230
-            new Transformations(...array_map(
231
-                static function (string $pattern, string $replacement) : Transformation {
232
-                    return new Transformation(new Pattern($pattern), $replacement);
230
+            new Transformations( ...array_map(
231
+                static function( string $pattern, string $replacement ) : Transformation {
232
+                    return new Transformation( new Pattern( $pattern ), $replacement );
233 233
                 },
234
-                array_keys($regular),
235
-                array_values($regular)
236
-            )),
237
-            new Patterns(...array_map(
238
-                static function (string $pattern) : Pattern {
239
-                    return new Pattern($pattern);
234
+                array_keys( $regular ),
235
+                array_values( $regular )
236
+            ) ),
237
+            new Patterns( ...array_map(
238
+                static function( string $pattern ) : Pattern {
239
+                    return new Pattern( $pattern );
240 240
                 },
241 241
                 $uninflected
242
-            )),
243
-            new Substitutions(...array_map(
244
-                static function (string $word, string $to) : Substitution {
245
-                    return new Substitution(new Word($word), new Word($to));
242
+            ) ),
243
+            new Substitutions( ...array_map(
244
+                static function( string $word, string $to ) : Substitution {
245
+                    return new Substitution( new Word( $word ), new Word( $to ) );
246 246
                 },
247
-                array_keys($irregular),
248
-                array_values($irregular)
249
-            ))
247
+                array_keys( $irregular ),
248
+                array_values( $irregular )
249
+            ) )
250 250
         );
251 251
     }
252 252
 
@@ -259,11 +259,11 @@  discard block
 block discarded – undo
259 259
      *
260 260
      * @deprecated
261 261
      */
262
-    public static function pluralize(string $word) : string
262
+    public static function pluralize( string $word ) : string
263 263
     {
264
-        @trigger_error(sprintf('The "%s" method is deprecated and will be dropped in doctrine/inflector 2.0. Please update to the new Inflector API.', __METHOD__), E_USER_DEPRECATED);
264
+        @trigger_error( sprintf( 'The "%s" method is deprecated and will be dropped in doctrine/inflector 2.0. Please update to the new Inflector API.', __METHOD__ ), E_USER_DEPRECATED );
265 265
 
266
-        return self::getInstance()->pluralize($word);
266
+        return self::getInstance()->pluralize( $word );
267 267
     }
268 268
 
269 269
     /**
@@ -275,10 +275,10 @@  discard block
 block discarded – undo
275 275
      *
276 276
      * @deprecated
277 277
      */
278
-    public static function singularize(string $word) : string
278
+    public static function singularize( string $word ) : string
279 279
     {
280
-        @trigger_error(sprintf('The "%s" method is deprecated and will be dropped in doctrine/inflector 2.0. Please update to the new Inflector API.', __METHOD__), E_USER_DEPRECATED);
280
+        @trigger_error( sprintf( 'The "%s" method is deprecated and will be dropped in doctrine/inflector 2.0. Please update to the new Inflector API.', __METHOD__ ), E_USER_DEPRECATED );
281 281
 
282
-        return self::getInstance()->singularize($word);
282
+        return self::getInstance()->singularize( $word );
283 283
     }
284 284
 }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -42,8 +42,7 @@
 block discarded – undo
42 42
 /**
43 43
  * @deprecated
44 44
  */
45
-class Inflector
46
-{
45
+class Inflector {
47 46
     /**
48 47
      * @var LanguageInflectorFactory|null
49 48
      */
Please login to merge, or discard this patch.
vendor/composer/composer/src/Composer/DependencyResolver/PoolOptimizer.php 3 patches
Indentation   +420 added lines, -420 removed lines patch added patch discarded remove patch
@@ -28,424 +28,424 @@
 block discarded – undo
28 28
  */
29 29
 class PoolOptimizer
30 30
 {
31
-    /**
32
-     * @var PolicyInterface
33
-     */
34
-    private $policy;
35
-
36
-    /**
37
-     * @var array<int, true>
38
-     */
39
-    private $irremovablePackages = array();
40
-
41
-    /**
42
-     * @var array<string, array<string, ConstraintInterface>>
43
-     */
44
-    private $requireConstraintsPerPackage = array();
45
-
46
-    /**
47
-     * @var array<string, array<string, ConstraintInterface>>
48
-     */
49
-    private $conflictConstraintsPerPackage = array();
50
-
51
-    /**
52
-     * @var array<int, true>
53
-     */
54
-    private $packagesToRemove = array();
55
-
56
-    /**
57
-     * @var array<int, BasePackage[]>
58
-     */
59
-    private $aliasesPerPackage = array();
60
-
61
-    /**
62
-     * @var array<string, array<string, string>>
63
-     */
64
-    private $removedVersionsByPackage = array();
65
-
66
-    public function __construct(PolicyInterface $policy)
67
-    {
68
-        $this->policy = $policy;
69
-    }
70
-
71
-    /**
72
-     * @return Pool
73
-     */
74
-    public function optimize(Request $request, Pool $pool)
75
-    {
76
-        $this->prepare($request, $pool);
77
-
78
-        $this->optimizeByIdenticalDependencies($request, $pool);
79
-
80
-        $this->optimizeImpossiblePackagesAway($request, $pool);
81
-
82
-        $optimizedPool = $this->applyRemovalsToPool($pool);
83
-
84
-        // No need to run this recursively at the moment
85
-        // because the current optimizations cannot provide
86
-        // even more gains when ran again. Might change
87
-        // in the future with additional optimizations.
88
-
89
-        $this->irremovablePackages = array();
90
-        $this->requireConstraintsPerPackage = array();
91
-        $this->conflictConstraintsPerPackage = array();
92
-        $this->packagesToRemove = array();
93
-        $this->aliasesPerPackage = array();
94
-        $this->removedVersionsByPackage = array();
95
-
96
-        return $optimizedPool;
97
-    }
98
-
99
-    /**
100
-     * @return void
101
-     */
102
-    private function prepare(Request $request, Pool $pool)
103
-    {
104
-        $irremovablePackageConstraintGroups = array();
105
-
106
-        // Mark fixed or locked packages as irremovable
107
-        foreach ($request->getFixedOrLockedPackages() as $package) {
108
-            $irremovablePackageConstraintGroups[$package->getName()][] = new Constraint('==', $package->getVersion());
109
-        }
110
-
111
-        // Extract requested package requirements
112
-        foreach ($request->getRequires() as $require => $constraint) {
113
-            $constraint = Intervals::compactConstraint($constraint);
114
-            $this->requireConstraintsPerPackage[$require][(string) $constraint] = $constraint;
115
-        }
116
-
117
-        // First pass over all packages to extract information and mark package constraints irremovable
118
-        foreach ($pool->getPackages() as $package) {
119
-            // Extract package requirements
120
-            foreach ($package->getRequires() as $link) {
121
-                $constraint = Intervals::compactConstraint($link->getConstraint());
122
-                $this->requireConstraintsPerPackage[$link->getTarget()][(string) $constraint] = $constraint;
123
-            }
124
-            // Extract package conflicts
125
-            foreach ($package->getConflicts() as $link) {
126
-                $constraint = Intervals::compactConstraint($link->getConstraint());
127
-                $this->conflictConstraintsPerPackage[$link->getTarget()][(string) $constraint] = $constraint;
128
-            }
129
-
130
-            // Keep track of alias packages for every package so if either the alias or aliased is kept
131
-            // we keep the others as they are a unit of packages really
132
-            if ($package instanceof AliasPackage) {
133
-                $this->aliasesPerPackage[$package->getAliasOf()->id][] = $package;
134
-            }
135
-        }
136
-
137
-        $irremovablePackageConstraints = array();
138
-        foreach ($irremovablePackageConstraintGroups as $packageName => $constraints) {
139
-            $irremovablePackageConstraints[$packageName] = 1 === \count($constraints) ? $constraints[0] : new MultiConstraint($constraints, false);
140
-        }
141
-        unset($irremovablePackageConstraintGroups);
142
-
143
-        // Mark the packages as irremovable based on the constraints
144
-        foreach ($pool->getPackages() as $package) {
145
-            if (!isset($irremovablePackageConstraints[$package->getName()])) {
146
-                continue;
147
-            }
148
-
149
-            if (CompilingMatcher::match($irremovablePackageConstraints[$package->getName()], Constraint::OP_EQ, $package->getVersion())) {
150
-                $this->markPackageIrremovable($package);
151
-            }
152
-        }
153
-    }
154
-
155
-    /**
156
-     * @return void
157
-     */
158
-    private function markPackageIrremovable(BasePackage $package)
159
-    {
160
-        $this->irremovablePackages[$package->id] = true;
161
-        if ($package instanceof AliasPackage) {
162
-            // recursing here so aliasesPerPackage for the aliasOf can be checked
163
-            // and all its aliases marked as irremovable as well
164
-            $this->markPackageIrremovable($package->getAliasOf());
165
-        }
166
-        if (isset($this->aliasesPerPackage[$package->id])) {
167
-            foreach ($this->aliasesPerPackage[$package->id] as $aliasPackage) {
168
-                $this->irremovablePackages[$aliasPackage->id] = true;
169
-            }
170
-        }
171
-    }
172
-
173
-    /**
174
-     * @return Pool Optimized pool
175
-     */
176
-    private function applyRemovalsToPool(Pool $pool)
177
-    {
178
-        $packages = array();
179
-        $removedVersions = array();
180
-        foreach ($pool->getPackages() as $package) {
181
-            if (!isset($this->packagesToRemove[$package->id])) {
182
-                $packages[] = $package;
183
-            } else {
184
-                $removedVersions[$package->getName()][$package->getVersion()] = $package->getPrettyVersion();
185
-            }
186
-        }
187
-
188
-        $optimizedPool = new Pool($packages, $pool->getUnacceptableFixedOrLockedPackages(), $removedVersions, $this->removedVersionsByPackage);
189
-
190
-        return $optimizedPool;
191
-    }
192
-
193
-    /**
194
-     * @return void
195
-     */
196
-    private function optimizeByIdenticalDependencies(Request $request, Pool $pool)
197
-    {
198
-        $identicalDefinitionsPerPackage = array();
199
-        $packageIdenticalDefinitionLookup = array();
200
-
201
-        foreach ($pool->getPackages() as $package) {
202
-
203
-            // If that package was already marked irremovable, we can skip
204
-            // the entire process for it
205
-            if (isset($this->irremovablePackages[$package->id])) {
206
-                continue;
207
-            }
208
-
209
-            $this->markPackageForRemoval($package->id);
210
-
211
-            $dependencyHash = $this->calculateDependencyHash($package);
212
-
213
-            foreach ($package->getNames(false) as $packageName) {
214
-
215
-                if (!isset($this->requireConstraintsPerPackage[$packageName])) {
216
-                    continue;
217
-                }
218
-
219
-                foreach ($this->requireConstraintsPerPackage[$packageName] as $requireConstraint) {
220
-                    $groupHashParts = array();
221
-
222
-                    if (CompilingMatcher::match($requireConstraint, Constraint::OP_EQ, $package->getVersion())) {
223
-                        $groupHashParts[] = 'require:' . (string) $requireConstraint;
224
-                    }
225
-
226
-                    if ($package->getReplaces()) {
227
-                        foreach ($package->getReplaces() as $link) {
228
-                            if (CompilingMatcher::match($link->getConstraint(), Constraint::OP_EQ, $package->getVersion())) {
229
-                                // Use the same hash part as the regular require hash because that's what the replacement does
230
-                                $groupHashParts[] = 'require:' . (string) $link->getConstraint();
231
-                            }
232
-                        }
233
-                    }
234
-
235
-                    if (isset($this->conflictConstraintsPerPackage[$packageName])) {
236
-                        foreach ($this->conflictConstraintsPerPackage[$packageName] as $conflictConstraint) {
237
-                            if (CompilingMatcher::match($conflictConstraint, Constraint::OP_EQ, $package->getVersion())) {
238
-                                $groupHashParts[] = 'conflict:' . (string) $conflictConstraint;
239
-                            }
240
-                        }
241
-                    }
242
-
243
-                    if (!$groupHashParts) {
244
-                        continue;
245
-                    }
246
-
247
-                    $groupHash = implode('', $groupHashParts);
248
-                    $identicalDefinitionsPerPackage[$packageName][$groupHash][$dependencyHash][] = $package;
249
-                    $packageIdenticalDefinitionLookup[$package->id][$packageName] = array('groupHash' => $groupHash, 'dependencyHash' => $dependencyHash);
250
-                }
251
-            }
252
-        }
253
-
254
-        foreach ($identicalDefinitionsPerPackage as $constraintGroups) {
255
-            foreach ($constraintGroups as $constraintGroup) {
256
-                foreach ($constraintGroup as $packages) {
257
-                    // Only one package in this constraint group has the same requirements, we're not allowed to remove that package
258
-                    if (1 === \count($packages)) {
259
-                        $this->keepPackage($packages[0], $identicalDefinitionsPerPackage, $packageIdenticalDefinitionLookup);
260
-                        continue;
261
-                    }
262
-
263
-                    // Otherwise we find out which one is the preferred package in this constraint group which is
264
-                    // then not allowed to be removed either
265
-                    $literals = array();
266
-
267
-                    foreach ($packages as $package) {
268
-                        $literals[] = $package->id;
269
-                    }
270
-
271
-                    foreach ($this->policy->selectPreferredPackages($pool, $literals) as $preferredLiteral) {
272
-                        $this->keepPackage($pool->literalToPackage($preferredLiteral), $identicalDefinitionsPerPackage, $packageIdenticalDefinitionLookup);
273
-                    }
274
-                }
275
-            }
276
-        }
277
-    }
278
-
279
-    /**
280
-     * @return string
281
-     */
282
-    private function calculateDependencyHash(BasePackage $package)
283
-    {
284
-        $hash = '';
285
-
286
-        $hashRelevantLinks = array(
287
-            'requires' => $package->getRequires(),
288
-            'conflicts' => $package->getConflicts(),
289
-            'replaces' => $package->getReplaces(),
290
-            'provides' => $package->getProvides()
291
-        );
292
-
293
-        foreach ($hashRelevantLinks as $key => $links) {
294
-            if (0 === \count($links)) {
295
-                continue;
296
-            }
297
-
298
-            // start new hash section
299
-            $hash .= $key . ':';
300
-
301
-            $subhash = array();
302
-
303
-            foreach ($links as $link) {
304
-                // To get the best dependency hash matches we should use Intervals::compactConstraint() here.
305
-                // However, the majority of projects are going to specify their constraints already pretty
306
-                // much in the best variant possible. In other words, we'd be wasting time here and it would actually hurt
307
-                // performance more than the additional few packages that could be filtered out would benefit the process.
308
-                $subhash[$link->getTarget()] = (string) $link->getConstraint();
309
-            }
310
-
311
-            // Sort for best result
312
-            ksort($subhash);
313
-
314
-            foreach ($subhash as $target => $constraint) {
315
-                $hash .= $target . '@' . $constraint;
316
-            }
317
-        }
318
-
319
-        return $hash;
320
-    }
321
-
322
-    /**
323
-     * @param int $id
324
-     * @return void
325
-     */
326
-    private function markPackageForRemoval($id)
327
-    {
328
-        // We are not allowed to remove packages if they have been marked as irremovable
329
-        if (isset($this->irremovablePackages[$id])) {
330
-            throw new \LogicException('Attempted removing a package which was previously marked irremovable');
331
-        }
332
-
333
-        $this->packagesToRemove[$id] = true;
334
-    }
335
-
336
-    /**
337
-     * @param array<string, array<string, array<string, list<BasePackage>>>> $identicalDefinitionsPerPackage
338
-     * @param array<int, array<string, array{groupHash: string, dependencyHash: string}>> $packageIdenticalDefinitionLookup
339
-     * @return void
340
-     */
341
-    private function keepPackage(BasePackage $package, $identicalDefinitionsPerPackage, $packageIdenticalDefinitionLookup)
342
-    {
343
-        unset($this->packagesToRemove[$package->id]);
344
-
345
-        if ($package instanceof AliasPackage) {
346
-            // recursing here so aliasesPerPackage for the aliasOf can be checked
347
-            // and all its aliases marked to be kept as well
348
-            $this->keepPackage($package->getAliasOf(), $identicalDefinitionsPerPackage, $packageIdenticalDefinitionLookup);
349
-        }
350
-
351
-        // record all the versions of the package group so we can list them later in Problem output
352
-        foreach ($package->getNames(false) as $name) {
353
-            if (isset($packageIdenticalDefinitionLookup[$package->id][$name])) {
354
-                $packageGroupPointers = $packageIdenticalDefinitionLookup[$package->id][$name];
355
-                $packageGroup = $identicalDefinitionsPerPackage[$name][$packageGroupPointers['groupHash']][$packageGroupPointers['dependencyHash']];
356
-                foreach ($packageGroup as $pkg) {
357
-                    if ($pkg instanceof AliasPackage && $pkg->getPrettyVersion() === VersionParser::DEFAULT_BRANCH_ALIAS) {
358
-                        $pkg = $pkg->getAliasOf();
359
-                    }
360
-                    $this->removedVersionsByPackage[spl_object_hash($package)][$pkg->getVersion()] = $pkg->getPrettyVersion();
361
-                }
362
-            }
363
-        }
364
-
365
-        if (isset($this->aliasesPerPackage[$package->id])) {
366
-            foreach ($this->aliasesPerPackage[$package->id] as $aliasPackage) {
367
-                unset($this->packagesToRemove[$aliasPackage->id]);
368
-
369
-                // record all the versions of the package group so we can list them later in Problem output
370
-                foreach ($aliasPackage->getNames(false) as $name) {
371
-                    if (isset($packageIdenticalDefinitionLookup[$aliasPackage->id][$name])) {
372
-                        $packageGroupPointers = $packageIdenticalDefinitionLookup[$aliasPackage->id][$name];
373
-                        $packageGroup = $identicalDefinitionsPerPackage[$name][$packageGroupPointers['groupHash']][$packageGroupPointers['dependencyHash']];
374
-                        foreach ($packageGroup as $pkg) {
375
-                            if ($pkg instanceof AliasPackage && $pkg->getPrettyVersion() === VersionParser::DEFAULT_BRANCH_ALIAS) {
376
-                                $pkg = $pkg->getAliasOf();
377
-                            }
378
-                            $this->removedVersionsByPackage[spl_object_hash($aliasPackage)][$pkg->getVersion()] = $pkg->getPrettyVersion();
379
-                        }
380
-                    }
381
-                }
382
-            }
383
-        }
384
-    }
385
-
386
-    /**
387
-     * Use the list of locked packages to constrain the loaded packages
388
-     * This will reduce packages with significant numbers of historical versions to a smaller number
389
-     * and reduce the resulting rule set that is generated
390
-     *
391
-     * @return void
392
-     */
393
-    private function optimizeImpossiblePackagesAway(Request $request, Pool $pool)
394
-    {
395
-        if (count($request->getLockedPackages()) === 0) {
396
-            return;
397
-        }
398
-
399
-        $packageIndex = array();
400
-
401
-        foreach ($pool->getPackages() as $package) {
402
-            $id = $package->id;
403
-
404
-            // Do not remove irremovable packages
405
-            if (isset($this->irremovablePackages[$id])) {
406
-                continue;
407
-            }
408
-            // Do not remove a package aliased by another package, nor aliases
409
-            if (isset($this->aliasesPerPackage[$id]) || $package instanceof AliasPackage) {
410
-                continue;
411
-            }
412
-            // Do not remove locked packages
413
-            if ($request->isFixedPackage($package) || $request->isLockedPackage($package)) {
414
-                continue;
415
-            }
416
-
417
-            $packageIndex[$package->getName()][$package->id] = $package;
418
-        }
419
-
420
-        foreach ($request->getLockedPackages() as $package) {
421
-            // If this locked package is no longer required by root or anything in the pool, it may get uninstalled so do not apply its requirements
422
-            // In a case where a requirement WERE to appear in the pool by a package that would not be used, it would've been unlocked and so not filtered still
423
-            $isUnusedPackage = true;
424
-            foreach ($package->getNames(false) as $packageName) {
425
-                if (isset($this->requireConstraintsPerPackage[$packageName])) {
426
-                    $isUnusedPackage = false;
427
-                    break;
428
-                }
429
-            }
430
-
431
-            if ($isUnusedPackage) {
432
-                continue;
433
-            }
434
-
435
-            foreach ($package->getRequires() as $link) {
436
-                $require = $link->getTarget();
437
-                if (!isset($packageIndex[$require])) {
438
-                    continue;
439
-                }
440
-
441
-                $linkConstraint = $link->getConstraint();
442
-                foreach ($packageIndex[$require] as $id => $requiredPkg) {
443
-                    if (false === CompilingMatcher::match($linkConstraint, Constraint::OP_EQ, $requiredPkg->getVersion())) {
444
-                        $this->markPackageForRemoval($id);
445
-                        unset($packageIndex[$require][$id]);
446
-                    }
447
-                }
448
-            }
449
-        }
450
-    }
31
+	/**
32
+	 * @var PolicyInterface
33
+	 */
34
+	private $policy;
35
+
36
+	/**
37
+	 * @var array<int, true>
38
+	 */
39
+	private $irremovablePackages = array();
40
+
41
+	/**
42
+	 * @var array<string, array<string, ConstraintInterface>>
43
+	 */
44
+	private $requireConstraintsPerPackage = array();
45
+
46
+	/**
47
+	 * @var array<string, array<string, ConstraintInterface>>
48
+	 */
49
+	private $conflictConstraintsPerPackage = array();
50
+
51
+	/**
52
+	 * @var array<int, true>
53
+	 */
54
+	private $packagesToRemove = array();
55
+
56
+	/**
57
+	 * @var array<int, BasePackage[]>
58
+	 */
59
+	private $aliasesPerPackage = array();
60
+
61
+	/**
62
+	 * @var array<string, array<string, string>>
63
+	 */
64
+	private $removedVersionsByPackage = array();
65
+
66
+	public function __construct(PolicyInterface $policy)
67
+	{
68
+		$this->policy = $policy;
69
+	}
70
+
71
+	/**
72
+	 * @return Pool
73
+	 */
74
+	public function optimize(Request $request, Pool $pool)
75
+	{
76
+		$this->prepare($request, $pool);
77
+
78
+		$this->optimizeByIdenticalDependencies($request, $pool);
79
+
80
+		$this->optimizeImpossiblePackagesAway($request, $pool);
81
+
82
+		$optimizedPool = $this->applyRemovalsToPool($pool);
83
+
84
+		// No need to run this recursively at the moment
85
+		// because the current optimizations cannot provide
86
+		// even more gains when ran again. Might change
87
+		// in the future with additional optimizations.
88
+
89
+		$this->irremovablePackages = array();
90
+		$this->requireConstraintsPerPackage = array();
91
+		$this->conflictConstraintsPerPackage = array();
92
+		$this->packagesToRemove = array();
93
+		$this->aliasesPerPackage = array();
94
+		$this->removedVersionsByPackage = array();
95
+
96
+		return $optimizedPool;
97
+	}
98
+
99
+	/**
100
+	 * @return void
101
+	 */
102
+	private function prepare(Request $request, Pool $pool)
103
+	{
104
+		$irremovablePackageConstraintGroups = array();
105
+
106
+		// Mark fixed or locked packages as irremovable
107
+		foreach ($request->getFixedOrLockedPackages() as $package) {
108
+			$irremovablePackageConstraintGroups[$package->getName()][] = new Constraint('==', $package->getVersion());
109
+		}
110
+
111
+		// Extract requested package requirements
112
+		foreach ($request->getRequires() as $require => $constraint) {
113
+			$constraint = Intervals::compactConstraint($constraint);
114
+			$this->requireConstraintsPerPackage[$require][(string) $constraint] = $constraint;
115
+		}
116
+
117
+		// First pass over all packages to extract information and mark package constraints irremovable
118
+		foreach ($pool->getPackages() as $package) {
119
+			// Extract package requirements
120
+			foreach ($package->getRequires() as $link) {
121
+				$constraint = Intervals::compactConstraint($link->getConstraint());
122
+				$this->requireConstraintsPerPackage[$link->getTarget()][(string) $constraint] = $constraint;
123
+			}
124
+			// Extract package conflicts
125
+			foreach ($package->getConflicts() as $link) {
126
+				$constraint = Intervals::compactConstraint($link->getConstraint());
127
+				$this->conflictConstraintsPerPackage[$link->getTarget()][(string) $constraint] = $constraint;
128
+			}
129
+
130
+			// Keep track of alias packages for every package so if either the alias or aliased is kept
131
+			// we keep the others as they are a unit of packages really
132
+			if ($package instanceof AliasPackage) {
133
+				$this->aliasesPerPackage[$package->getAliasOf()->id][] = $package;
134
+			}
135
+		}
136
+
137
+		$irremovablePackageConstraints = array();
138
+		foreach ($irremovablePackageConstraintGroups as $packageName => $constraints) {
139
+			$irremovablePackageConstraints[$packageName] = 1 === \count($constraints) ? $constraints[0] : new MultiConstraint($constraints, false);
140
+		}
141
+		unset($irremovablePackageConstraintGroups);
142
+
143
+		// Mark the packages as irremovable based on the constraints
144
+		foreach ($pool->getPackages() as $package) {
145
+			if (!isset($irremovablePackageConstraints[$package->getName()])) {
146
+				continue;
147
+			}
148
+
149
+			if (CompilingMatcher::match($irremovablePackageConstraints[$package->getName()], Constraint::OP_EQ, $package->getVersion())) {
150
+				$this->markPackageIrremovable($package);
151
+			}
152
+		}
153
+	}
154
+
155
+	/**
156
+	 * @return void
157
+	 */
158
+	private function markPackageIrremovable(BasePackage $package)
159
+	{
160
+		$this->irremovablePackages[$package->id] = true;
161
+		if ($package instanceof AliasPackage) {
162
+			// recursing here so aliasesPerPackage for the aliasOf can be checked
163
+			// and all its aliases marked as irremovable as well
164
+			$this->markPackageIrremovable($package->getAliasOf());
165
+		}
166
+		if (isset($this->aliasesPerPackage[$package->id])) {
167
+			foreach ($this->aliasesPerPackage[$package->id] as $aliasPackage) {
168
+				$this->irremovablePackages[$aliasPackage->id] = true;
169
+			}
170
+		}
171
+	}
172
+
173
+	/**
174
+	 * @return Pool Optimized pool
175
+	 */
176
+	private function applyRemovalsToPool(Pool $pool)
177
+	{
178
+		$packages = array();
179
+		$removedVersions = array();
180
+		foreach ($pool->getPackages() as $package) {
181
+			if (!isset($this->packagesToRemove[$package->id])) {
182
+				$packages[] = $package;
183
+			} else {
184
+				$removedVersions[$package->getName()][$package->getVersion()] = $package->getPrettyVersion();
185
+			}
186
+		}
187
+
188
+		$optimizedPool = new Pool($packages, $pool->getUnacceptableFixedOrLockedPackages(), $removedVersions, $this->removedVersionsByPackage);
189
+
190
+		return $optimizedPool;
191
+	}
192
+
193
+	/**
194
+	 * @return void
195
+	 */
196
+	private function optimizeByIdenticalDependencies(Request $request, Pool $pool)
197
+	{
198
+		$identicalDefinitionsPerPackage = array();
199
+		$packageIdenticalDefinitionLookup = array();
200
+
201
+		foreach ($pool->getPackages() as $package) {
202
+
203
+			// If that package was already marked irremovable, we can skip
204
+			// the entire process for it
205
+			if (isset($this->irremovablePackages[$package->id])) {
206
+				continue;
207
+			}
208
+
209
+			$this->markPackageForRemoval($package->id);
210
+
211
+			$dependencyHash = $this->calculateDependencyHash($package);
212
+
213
+			foreach ($package->getNames(false) as $packageName) {
214
+
215
+				if (!isset($this->requireConstraintsPerPackage[$packageName])) {
216
+					continue;
217
+				}
218
+
219
+				foreach ($this->requireConstraintsPerPackage[$packageName] as $requireConstraint) {
220
+					$groupHashParts = array();
221
+
222
+					if (CompilingMatcher::match($requireConstraint, Constraint::OP_EQ, $package->getVersion())) {
223
+						$groupHashParts[] = 'require:' . (string) $requireConstraint;
224
+					}
225
+
226
+					if ($package->getReplaces()) {
227
+						foreach ($package->getReplaces() as $link) {
228
+							if (CompilingMatcher::match($link->getConstraint(), Constraint::OP_EQ, $package->getVersion())) {
229
+								// Use the same hash part as the regular require hash because that's what the replacement does
230
+								$groupHashParts[] = 'require:' . (string) $link->getConstraint();
231
+							}
232
+						}
233
+					}
234
+
235
+					if (isset($this->conflictConstraintsPerPackage[$packageName])) {
236
+						foreach ($this->conflictConstraintsPerPackage[$packageName] as $conflictConstraint) {
237
+							if (CompilingMatcher::match($conflictConstraint, Constraint::OP_EQ, $package->getVersion())) {
238
+								$groupHashParts[] = 'conflict:' . (string) $conflictConstraint;
239
+							}
240
+						}
241
+					}
242
+
243
+					if (!$groupHashParts) {
244
+						continue;
245
+					}
246
+
247
+					$groupHash = implode('', $groupHashParts);
248
+					$identicalDefinitionsPerPackage[$packageName][$groupHash][$dependencyHash][] = $package;
249
+					$packageIdenticalDefinitionLookup[$package->id][$packageName] = array('groupHash' => $groupHash, 'dependencyHash' => $dependencyHash);
250
+				}
251
+			}
252
+		}
253
+
254
+		foreach ($identicalDefinitionsPerPackage as $constraintGroups) {
255
+			foreach ($constraintGroups as $constraintGroup) {
256
+				foreach ($constraintGroup as $packages) {
257
+					// Only one package in this constraint group has the same requirements, we're not allowed to remove that package
258
+					if (1 === \count($packages)) {
259
+						$this->keepPackage($packages[0], $identicalDefinitionsPerPackage, $packageIdenticalDefinitionLookup);
260
+						continue;
261
+					}
262
+
263
+					// Otherwise we find out which one is the preferred package in this constraint group which is
264
+					// then not allowed to be removed either
265
+					$literals = array();
266
+
267
+					foreach ($packages as $package) {
268
+						$literals[] = $package->id;
269
+					}
270
+
271
+					foreach ($this->policy->selectPreferredPackages($pool, $literals) as $preferredLiteral) {
272
+						$this->keepPackage($pool->literalToPackage($preferredLiteral), $identicalDefinitionsPerPackage, $packageIdenticalDefinitionLookup);
273
+					}
274
+				}
275
+			}
276
+		}
277
+	}
278
+
279
+	/**
280
+	 * @return string
281
+	 */
282
+	private function calculateDependencyHash(BasePackage $package)
283
+	{
284
+		$hash = '';
285
+
286
+		$hashRelevantLinks = array(
287
+			'requires' => $package->getRequires(),
288
+			'conflicts' => $package->getConflicts(),
289
+			'replaces' => $package->getReplaces(),
290
+			'provides' => $package->getProvides()
291
+		);
292
+
293
+		foreach ($hashRelevantLinks as $key => $links) {
294
+			if (0 === \count($links)) {
295
+				continue;
296
+			}
297
+
298
+			// start new hash section
299
+			$hash .= $key . ':';
300
+
301
+			$subhash = array();
302
+
303
+			foreach ($links as $link) {
304
+				// To get the best dependency hash matches we should use Intervals::compactConstraint() here.
305
+				// However, the majority of projects are going to specify their constraints already pretty
306
+				// much in the best variant possible. In other words, we'd be wasting time here and it would actually hurt
307
+				// performance more than the additional few packages that could be filtered out would benefit the process.
308
+				$subhash[$link->getTarget()] = (string) $link->getConstraint();
309
+			}
310
+
311
+			// Sort for best result
312
+			ksort($subhash);
313
+
314
+			foreach ($subhash as $target => $constraint) {
315
+				$hash .= $target . '@' . $constraint;
316
+			}
317
+		}
318
+
319
+		return $hash;
320
+	}
321
+
322
+	/**
323
+	 * @param int $id
324
+	 * @return void
325
+	 */
326
+	private function markPackageForRemoval($id)
327
+	{
328
+		// We are not allowed to remove packages if they have been marked as irremovable
329
+		if (isset($this->irremovablePackages[$id])) {
330
+			throw new \LogicException('Attempted removing a package which was previously marked irremovable');
331
+		}
332
+
333
+		$this->packagesToRemove[$id] = true;
334
+	}
335
+
336
+	/**
337
+	 * @param array<string, array<string, array<string, list<BasePackage>>>> $identicalDefinitionsPerPackage
338
+	 * @param array<int, array<string, array{groupHash: string, dependencyHash: string}>> $packageIdenticalDefinitionLookup
339
+	 * @return void
340
+	 */
341
+	private function keepPackage(BasePackage $package, $identicalDefinitionsPerPackage, $packageIdenticalDefinitionLookup)
342
+	{
343
+		unset($this->packagesToRemove[$package->id]);
344
+
345
+		if ($package instanceof AliasPackage) {
346
+			// recursing here so aliasesPerPackage for the aliasOf can be checked
347
+			// and all its aliases marked to be kept as well
348
+			$this->keepPackage($package->getAliasOf(), $identicalDefinitionsPerPackage, $packageIdenticalDefinitionLookup);
349
+		}
350
+
351
+		// record all the versions of the package group so we can list them later in Problem output
352
+		foreach ($package->getNames(false) as $name) {
353
+			if (isset($packageIdenticalDefinitionLookup[$package->id][$name])) {
354
+				$packageGroupPointers = $packageIdenticalDefinitionLookup[$package->id][$name];
355
+				$packageGroup = $identicalDefinitionsPerPackage[$name][$packageGroupPointers['groupHash']][$packageGroupPointers['dependencyHash']];
356
+				foreach ($packageGroup as $pkg) {
357
+					if ($pkg instanceof AliasPackage && $pkg->getPrettyVersion() === VersionParser::DEFAULT_BRANCH_ALIAS) {
358
+						$pkg = $pkg->getAliasOf();
359
+					}
360
+					$this->removedVersionsByPackage[spl_object_hash($package)][$pkg->getVersion()] = $pkg->getPrettyVersion();
361
+				}
362
+			}
363
+		}
364
+
365
+		if (isset($this->aliasesPerPackage[$package->id])) {
366
+			foreach ($this->aliasesPerPackage[$package->id] as $aliasPackage) {
367
+				unset($this->packagesToRemove[$aliasPackage->id]);
368
+
369
+				// record all the versions of the package group so we can list them later in Problem output
370
+				foreach ($aliasPackage->getNames(false) as $name) {
371
+					if (isset($packageIdenticalDefinitionLookup[$aliasPackage->id][$name])) {
372
+						$packageGroupPointers = $packageIdenticalDefinitionLookup[$aliasPackage->id][$name];
373
+						$packageGroup = $identicalDefinitionsPerPackage[$name][$packageGroupPointers['groupHash']][$packageGroupPointers['dependencyHash']];
374
+						foreach ($packageGroup as $pkg) {
375
+							if ($pkg instanceof AliasPackage && $pkg->getPrettyVersion() === VersionParser::DEFAULT_BRANCH_ALIAS) {
376
+								$pkg = $pkg->getAliasOf();
377
+							}
378
+							$this->removedVersionsByPackage[spl_object_hash($aliasPackage)][$pkg->getVersion()] = $pkg->getPrettyVersion();
379
+						}
380
+					}
381
+				}
382
+			}
383
+		}
384
+	}
385
+
386
+	/**
387
+	 * Use the list of locked packages to constrain the loaded packages
388
+	 * This will reduce packages with significant numbers of historical versions to a smaller number
389
+	 * and reduce the resulting rule set that is generated
390
+	 *
391
+	 * @return void
392
+	 */
393
+	private function optimizeImpossiblePackagesAway(Request $request, Pool $pool)
394
+	{
395
+		if (count($request->getLockedPackages()) === 0) {
396
+			return;
397
+		}
398
+
399
+		$packageIndex = array();
400
+
401
+		foreach ($pool->getPackages() as $package) {
402
+			$id = $package->id;
403
+
404
+			// Do not remove irremovable packages
405
+			if (isset($this->irremovablePackages[$id])) {
406
+				continue;
407
+			}
408
+			// Do not remove a package aliased by another package, nor aliases
409
+			if (isset($this->aliasesPerPackage[$id]) || $package instanceof AliasPackage) {
410
+				continue;
411
+			}
412
+			// Do not remove locked packages
413
+			if ($request->isFixedPackage($package) || $request->isLockedPackage($package)) {
414
+				continue;
415
+			}
416
+
417
+			$packageIndex[$package->getName()][$package->id] = $package;
418
+		}
419
+
420
+		foreach ($request->getLockedPackages() as $package) {
421
+			// If this locked package is no longer required by root or anything in the pool, it may get uninstalled so do not apply its requirements
422
+			// In a case where a requirement WERE to appear in the pool by a package that would not be used, it would've been unlocked and so not filtered still
423
+			$isUnusedPackage = true;
424
+			foreach ($package->getNames(false) as $packageName) {
425
+				if (isset($this->requireConstraintsPerPackage[$packageName])) {
426
+					$isUnusedPackage = false;
427
+					break;
428
+				}
429
+			}
430
+
431
+			if ($isUnusedPackage) {
432
+				continue;
433
+			}
434
+
435
+			foreach ($package->getRequires() as $link) {
436
+				$require = $link->getTarget();
437
+				if (!isset($packageIndex[$require])) {
438
+					continue;
439
+				}
440
+
441
+				$linkConstraint = $link->getConstraint();
442
+				foreach ($packageIndex[$require] as $id => $requiredPkg) {
443
+					if (false === CompilingMatcher::match($linkConstraint, Constraint::OP_EQ, $requiredPkg->getVersion())) {
444
+						$this->markPackageForRemoval($id);
445
+						unset($packageIndex[$require][$id]);
446
+					}
447
+				}
448
+			}
449
+		}
450
+	}
451 451
 }
Please login to merge, or discard this patch.
Spacing   +121 added lines, -121 removed lines patch added patch discarded remove patch
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
      */
64 64
     private $removedVersionsByPackage = array();
65 65
 
66
-    public function __construct(PolicyInterface $policy)
66
+    public function __construct( PolicyInterface $policy )
67 67
     {
68 68
         $this->policy = $policy;
69 69
     }
@@ -71,15 +71,15 @@  discard block
 block discarded – undo
71 71
     /**
72 72
      * @return Pool
73 73
      */
74
-    public function optimize(Request $request, Pool $pool)
74
+    public function optimize( Request $request, Pool $pool )
75 75
     {
76
-        $this->prepare($request, $pool);
76
+        $this->prepare( $request, $pool );
77 77
 
78
-        $this->optimizeByIdenticalDependencies($request, $pool);
78
+        $this->optimizeByIdenticalDependencies( $request, $pool );
79 79
 
80
-        $this->optimizeImpossiblePackagesAway($request, $pool);
80
+        $this->optimizeImpossiblePackagesAway( $request, $pool );
81 81
 
82
-        $optimizedPool = $this->applyRemovalsToPool($pool);
82
+        $optimizedPool = $this->applyRemovalsToPool( $pool );
83 83
 
84 84
         // No need to run this recursively at the moment
85 85
         // because the current optimizations cannot provide
@@ -99,55 +99,55 @@  discard block
 block discarded – undo
99 99
     /**
100 100
      * @return void
101 101
      */
102
-    private function prepare(Request $request, Pool $pool)
102
+    private function prepare( Request $request, Pool $pool )
103 103
     {
104 104
         $irremovablePackageConstraintGroups = array();
105 105
 
106 106
         // Mark fixed or locked packages as irremovable
107
-        foreach ($request->getFixedOrLockedPackages() as $package) {
108
-            $irremovablePackageConstraintGroups[$package->getName()][] = new Constraint('==', $package->getVersion());
107
+        foreach ( $request->getFixedOrLockedPackages() as $package ) {
108
+            $irremovablePackageConstraintGroups[ $package->getName() ][ ] = new Constraint( '==', $package->getVersion() );
109 109
         }
110 110
 
111 111
         // Extract requested package requirements
112
-        foreach ($request->getRequires() as $require => $constraint) {
113
-            $constraint = Intervals::compactConstraint($constraint);
114
-            $this->requireConstraintsPerPackage[$require][(string) $constraint] = $constraint;
112
+        foreach ( $request->getRequires() as $require => $constraint ) {
113
+            $constraint = Intervals::compactConstraint( $constraint );
114
+            $this->requireConstraintsPerPackage[ $require ][ (string)$constraint ] = $constraint;
115 115
         }
116 116
 
117 117
         // First pass over all packages to extract information and mark package constraints irremovable
118
-        foreach ($pool->getPackages() as $package) {
118
+        foreach ( $pool->getPackages() as $package ) {
119 119
             // Extract package requirements
120
-            foreach ($package->getRequires() as $link) {
121
-                $constraint = Intervals::compactConstraint($link->getConstraint());
122
-                $this->requireConstraintsPerPackage[$link->getTarget()][(string) $constraint] = $constraint;
120
+            foreach ( $package->getRequires() as $link ) {
121
+                $constraint = Intervals::compactConstraint( $link->getConstraint() );
122
+                $this->requireConstraintsPerPackage[ $link->getTarget() ][ (string)$constraint ] = $constraint;
123 123
             }
124 124
             // Extract package conflicts
125
-            foreach ($package->getConflicts() as $link) {
126
-                $constraint = Intervals::compactConstraint($link->getConstraint());
127
-                $this->conflictConstraintsPerPackage[$link->getTarget()][(string) $constraint] = $constraint;
125
+            foreach ( $package->getConflicts() as $link ) {
126
+                $constraint = Intervals::compactConstraint( $link->getConstraint() );
127
+                $this->conflictConstraintsPerPackage[ $link->getTarget() ][ (string)$constraint ] = $constraint;
128 128
             }
129 129
 
130 130
             // Keep track of alias packages for every package so if either the alias or aliased is kept
131 131
             // we keep the others as they are a unit of packages really
132
-            if ($package instanceof AliasPackage) {
133
-                $this->aliasesPerPackage[$package->getAliasOf()->id][] = $package;
132
+            if ( $package instanceof AliasPackage ) {
133
+                $this->aliasesPerPackage[ $package->getAliasOf()->id ][ ] = $package;
134 134
             }
135 135
         }
136 136
 
137 137
         $irremovablePackageConstraints = array();
138
-        foreach ($irremovablePackageConstraintGroups as $packageName => $constraints) {
139
-            $irremovablePackageConstraints[$packageName] = 1 === \count($constraints) ? $constraints[0] : new MultiConstraint($constraints, false);
138
+        foreach ( $irremovablePackageConstraintGroups as $packageName => $constraints ) {
139
+            $irremovablePackageConstraints[ $packageName ] = 1 === \count( $constraints ) ? $constraints[ 0 ] : new MultiConstraint( $constraints, false );
140 140
         }
141
-        unset($irremovablePackageConstraintGroups);
141
+        unset( $irremovablePackageConstraintGroups );
142 142
 
143 143
         // Mark the packages as irremovable based on the constraints
144
-        foreach ($pool->getPackages() as $package) {
145
-            if (!isset($irremovablePackageConstraints[$package->getName()])) {
144
+        foreach ( $pool->getPackages() as $package ) {
145
+            if ( ! isset( $irremovablePackageConstraints[ $package->getName() ] ) ) {
146 146
                 continue;
147 147
             }
148 148
 
149
-            if (CompilingMatcher::match($irremovablePackageConstraints[$package->getName()], Constraint::OP_EQ, $package->getVersion())) {
150
-                $this->markPackageIrremovable($package);
149
+            if ( CompilingMatcher::match( $irremovablePackageConstraints[ $package->getName() ], Constraint::OP_EQ, $package->getVersion() ) ) {
150
+                $this->markPackageIrremovable( $package );
151 151
             }
152 152
         }
153 153
     }
@@ -155,17 +155,17 @@  discard block
 block discarded – undo
155 155
     /**
156 156
      * @return void
157 157
      */
158
-    private function markPackageIrremovable(BasePackage $package)
158
+    private function markPackageIrremovable( BasePackage $package )
159 159
     {
160
-        $this->irremovablePackages[$package->id] = true;
161
-        if ($package instanceof AliasPackage) {
160
+        $this->irremovablePackages[ $package->id ] = true;
161
+        if ( $package instanceof AliasPackage ) {
162 162
             // recursing here so aliasesPerPackage for the aliasOf can be checked
163 163
             // and all its aliases marked as irremovable as well
164
-            $this->markPackageIrremovable($package->getAliasOf());
164
+            $this->markPackageIrremovable( $package->getAliasOf() );
165 165
         }
166
-        if (isset($this->aliasesPerPackage[$package->id])) {
167
-            foreach ($this->aliasesPerPackage[$package->id] as $aliasPackage) {
168
-                $this->irremovablePackages[$aliasPackage->id] = true;
166
+        if ( isset( $this->aliasesPerPackage[ $package->id ] ) ) {
167
+            foreach ( $this->aliasesPerPackage[ $package->id ] as $aliasPackage ) {
168
+                $this->irremovablePackages[ $aliasPackage->id ] = true;
169 169
             }
170 170
         }
171 171
     }
@@ -173,19 +173,19 @@  discard block
 block discarded – undo
173 173
     /**
174 174
      * @return Pool Optimized pool
175 175
      */
176
-    private function applyRemovalsToPool(Pool $pool)
176
+    private function applyRemovalsToPool( Pool $pool )
177 177
     {
178 178
         $packages = array();
179 179
         $removedVersions = array();
180
-        foreach ($pool->getPackages() as $package) {
181
-            if (!isset($this->packagesToRemove[$package->id])) {
182
-                $packages[] = $package;
180
+        foreach ( $pool->getPackages() as $package ) {
181
+            if ( ! isset( $this->packagesToRemove[ $package->id ] ) ) {
182
+                $packages[ ] = $package;
183 183
             } else {
184
-                $removedVersions[$package->getName()][$package->getVersion()] = $package->getPrettyVersion();
184
+                $removedVersions[ $package->getName() ][ $package->getVersion() ] = $package->getPrettyVersion();
185 185
             }
186 186
         }
187 187
 
188
-        $optimizedPool = new Pool($packages, $pool->getUnacceptableFixedOrLockedPackages(), $removedVersions, $this->removedVersionsByPackage);
188
+        $optimizedPool = new Pool( $packages, $pool->getUnacceptableFixedOrLockedPackages(), $removedVersions, $this->removedVersionsByPackage );
189 189
 
190 190
         return $optimizedPool;
191 191
     }
@@ -193,70 +193,70 @@  discard block
 block discarded – undo
193 193
     /**
194 194
      * @return void
195 195
      */
196
-    private function optimizeByIdenticalDependencies(Request $request, Pool $pool)
196
+    private function optimizeByIdenticalDependencies( Request $request, Pool $pool )
197 197
     {
198 198
         $identicalDefinitionsPerPackage = array();
199 199
         $packageIdenticalDefinitionLookup = array();
200 200
 
201
-        foreach ($pool->getPackages() as $package) {
201
+        foreach ( $pool->getPackages() as $package ) {
202 202
 
203 203
             // If that package was already marked irremovable, we can skip
204 204
             // the entire process for it
205
-            if (isset($this->irremovablePackages[$package->id])) {
205
+            if ( isset( $this->irremovablePackages[ $package->id ] ) ) {
206 206
                 continue;
207 207
             }
208 208
 
209
-            $this->markPackageForRemoval($package->id);
209
+            $this->markPackageForRemoval( $package->id );
210 210
 
211
-            $dependencyHash = $this->calculateDependencyHash($package);
211
+            $dependencyHash = $this->calculateDependencyHash( $package );
212 212
 
213
-            foreach ($package->getNames(false) as $packageName) {
213
+            foreach ( $package->getNames( false ) as $packageName ) {
214 214
 
215
-                if (!isset($this->requireConstraintsPerPackage[$packageName])) {
215
+                if ( ! isset( $this->requireConstraintsPerPackage[ $packageName ] ) ) {
216 216
                     continue;
217 217
                 }
218 218
 
219
-                foreach ($this->requireConstraintsPerPackage[$packageName] as $requireConstraint) {
219
+                foreach ( $this->requireConstraintsPerPackage[ $packageName ] as $requireConstraint ) {
220 220
                     $groupHashParts = array();
221 221
 
222
-                    if (CompilingMatcher::match($requireConstraint, Constraint::OP_EQ, $package->getVersion())) {
223
-                        $groupHashParts[] = 'require:' . (string) $requireConstraint;
222
+                    if ( CompilingMatcher::match( $requireConstraint, Constraint::OP_EQ, $package->getVersion() ) ) {
223
+                        $groupHashParts[ ] = 'require:' . (string)$requireConstraint;
224 224
                     }
225 225
 
226
-                    if ($package->getReplaces()) {
227
-                        foreach ($package->getReplaces() as $link) {
228
-                            if (CompilingMatcher::match($link->getConstraint(), Constraint::OP_EQ, $package->getVersion())) {
226
+                    if ( $package->getReplaces() ) {
227
+                        foreach ( $package->getReplaces() as $link ) {
228
+                            if ( CompilingMatcher::match( $link->getConstraint(), Constraint::OP_EQ, $package->getVersion() ) ) {
229 229
                                 // Use the same hash part as the regular require hash because that's what the replacement does
230
-                                $groupHashParts[] = 'require:' . (string) $link->getConstraint();
230
+                                $groupHashParts[ ] = 'require:' . (string)$link->getConstraint();
231 231
                             }
232 232
                         }
233 233
                     }
234 234
 
235
-                    if (isset($this->conflictConstraintsPerPackage[$packageName])) {
236
-                        foreach ($this->conflictConstraintsPerPackage[$packageName] as $conflictConstraint) {
237
-                            if (CompilingMatcher::match($conflictConstraint, Constraint::OP_EQ, $package->getVersion())) {
238
-                                $groupHashParts[] = 'conflict:' . (string) $conflictConstraint;
235
+                    if ( isset( $this->conflictConstraintsPerPackage[ $packageName ] ) ) {
236
+                        foreach ( $this->conflictConstraintsPerPackage[ $packageName ] as $conflictConstraint ) {
237
+                            if ( CompilingMatcher::match( $conflictConstraint, Constraint::OP_EQ, $package->getVersion() ) ) {
238
+                                $groupHashParts[ ] = 'conflict:' . (string)$conflictConstraint;
239 239
                             }
240 240
                         }
241 241
                     }
242 242
 
243
-                    if (!$groupHashParts) {
243
+                    if ( ! $groupHashParts ) {
244 244
                         continue;
245 245
                     }
246 246
 
247
-                    $groupHash = implode('', $groupHashParts);
248
-                    $identicalDefinitionsPerPackage[$packageName][$groupHash][$dependencyHash][] = $package;
249
-                    $packageIdenticalDefinitionLookup[$package->id][$packageName] = array('groupHash' => $groupHash, 'dependencyHash' => $dependencyHash);
247
+                    $groupHash = implode( '', $groupHashParts );
248
+                    $identicalDefinitionsPerPackage[ $packageName ][ $groupHash ][ $dependencyHash ][ ] = $package;
249
+                    $packageIdenticalDefinitionLookup[ $package->id ][ $packageName ] = array( 'groupHash' => $groupHash, 'dependencyHash' => $dependencyHash );
250 250
                 }
251 251
             }
252 252
         }
253 253
 
254
-        foreach ($identicalDefinitionsPerPackage as $constraintGroups) {
255
-            foreach ($constraintGroups as $constraintGroup) {
256
-                foreach ($constraintGroup as $packages) {
254
+        foreach ( $identicalDefinitionsPerPackage as $constraintGroups ) {
255
+            foreach ( $constraintGroups as $constraintGroup ) {
256
+                foreach ( $constraintGroup as $packages ) {
257 257
                     // Only one package in this constraint group has the same requirements, we're not allowed to remove that package
258
-                    if (1 === \count($packages)) {
259
-                        $this->keepPackage($packages[0], $identicalDefinitionsPerPackage, $packageIdenticalDefinitionLookup);
258
+                    if ( 1 === \count( $packages ) ) {
259
+                        $this->keepPackage( $packages[ 0 ], $identicalDefinitionsPerPackage, $packageIdenticalDefinitionLookup );
260 260
                         continue;
261 261
                     }
262 262
 
@@ -264,12 +264,12 @@  discard block
 block discarded – undo
264 264
                     // then not allowed to be removed either
265 265
                     $literals = array();
266 266
 
267
-                    foreach ($packages as $package) {
268
-                        $literals[] = $package->id;
267
+                    foreach ( $packages as $package ) {
268
+                        $literals[ ] = $package->id;
269 269
                     }
270 270
 
271
-                    foreach ($this->policy->selectPreferredPackages($pool, $literals) as $preferredLiteral) {
272
-                        $this->keepPackage($pool->literalToPackage($preferredLiteral), $identicalDefinitionsPerPackage, $packageIdenticalDefinitionLookup);
271
+                    foreach ( $this->policy->selectPreferredPackages( $pool, $literals ) as $preferredLiteral ) {
272
+                        $this->keepPackage( $pool->literalToPackage( $preferredLiteral ), $identicalDefinitionsPerPackage, $packageIdenticalDefinitionLookup );
273 273
                     }
274 274
                 }
275 275
             }
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
     /**
280 280
      * @return string
281 281
      */
282
-    private function calculateDependencyHash(BasePackage $package)
282
+    private function calculateDependencyHash( BasePackage $package )
283 283
     {
284 284
         $hash = '';
285 285
 
@@ -290,8 +290,8 @@  discard block
 block discarded – undo
290 290
             'provides' => $package->getProvides()
291 291
         );
292 292
 
293
-        foreach ($hashRelevantLinks as $key => $links) {
294
-            if (0 === \count($links)) {
293
+        foreach ( $hashRelevantLinks as $key => $links ) {
294
+            if ( 0 === \count( $links ) ) {
295 295
                 continue;
296 296
             }
297 297
 
@@ -300,18 +300,18 @@  discard block
 block discarded – undo
300 300
 
301 301
             $subhash = array();
302 302
 
303
-            foreach ($links as $link) {
303
+            foreach ( $links as $link ) {
304 304
                 // To get the best dependency hash matches we should use Intervals::compactConstraint() here.
305 305
                 // However, the majority of projects are going to specify their constraints already pretty
306 306
                 // much in the best variant possible. In other words, we'd be wasting time here and it would actually hurt
307 307
                 // performance more than the additional few packages that could be filtered out would benefit the process.
308
-                $subhash[$link->getTarget()] = (string) $link->getConstraint();
308
+                $subhash[ $link->getTarget() ] = (string)$link->getConstraint();
309 309
             }
310 310
 
311 311
             // Sort for best result
312
-            ksort($subhash);
312
+            ksort( $subhash );
313 313
 
314
-            foreach ($subhash as $target => $constraint) {
314
+            foreach ( $subhash as $target => $constraint ) {
315 315
                 $hash .= $target . '@' . $constraint;
316 316
             }
317 317
         }
@@ -323,14 +323,14 @@  discard block
 block discarded – undo
323 323
      * @param int $id
324 324
      * @return void
325 325
      */
326
-    private function markPackageForRemoval($id)
326
+    private function markPackageForRemoval( $id )
327 327
     {
328 328
         // We are not allowed to remove packages if they have been marked as irremovable
329
-        if (isset($this->irremovablePackages[$id])) {
330
-            throw new \LogicException('Attempted removing a package which was previously marked irremovable');
329
+        if ( isset( $this->irremovablePackages[ $id ] ) ) {
330
+            throw new \LogicException( 'Attempted removing a package which was previously marked irremovable' );
331 331
         }
332 332
 
333
-        $this->packagesToRemove[$id] = true;
333
+        $this->packagesToRemove[ $id ] = true;
334 334
     }
335 335
 
336 336
     /**
@@ -338,44 +338,44 @@  discard block
 block discarded – undo
338 338
      * @param array<int, array<string, array{groupHash: string, dependencyHash: string}>> $packageIdenticalDefinitionLookup
339 339
      * @return void
340 340
      */
341
-    private function keepPackage(BasePackage $package, $identicalDefinitionsPerPackage, $packageIdenticalDefinitionLookup)
341
+    private function keepPackage( BasePackage $package, $identicalDefinitionsPerPackage, $packageIdenticalDefinitionLookup )
342 342
     {
343
-        unset($this->packagesToRemove[$package->id]);
343
+        unset( $this->packagesToRemove[ $package->id ] );
344 344
 
345
-        if ($package instanceof AliasPackage) {
345
+        if ( $package instanceof AliasPackage ) {
346 346
             // recursing here so aliasesPerPackage for the aliasOf can be checked
347 347
             // and all its aliases marked to be kept as well
348
-            $this->keepPackage($package->getAliasOf(), $identicalDefinitionsPerPackage, $packageIdenticalDefinitionLookup);
348
+            $this->keepPackage( $package->getAliasOf(), $identicalDefinitionsPerPackage, $packageIdenticalDefinitionLookup );
349 349
         }
350 350
 
351 351
         // record all the versions of the package group so we can list them later in Problem output
352
-        foreach ($package->getNames(false) as $name) {
353
-            if (isset($packageIdenticalDefinitionLookup[$package->id][$name])) {
354
-                $packageGroupPointers = $packageIdenticalDefinitionLookup[$package->id][$name];
355
-                $packageGroup = $identicalDefinitionsPerPackage[$name][$packageGroupPointers['groupHash']][$packageGroupPointers['dependencyHash']];
356
-                foreach ($packageGroup as $pkg) {
357
-                    if ($pkg instanceof AliasPackage && $pkg->getPrettyVersion() === VersionParser::DEFAULT_BRANCH_ALIAS) {
352
+        foreach ( $package->getNames( false ) as $name ) {
353
+            if ( isset( $packageIdenticalDefinitionLookup[ $package->id ][ $name ] ) ) {
354
+                $packageGroupPointers = $packageIdenticalDefinitionLookup[ $package->id ][ $name ];
355
+                $packageGroup = $identicalDefinitionsPerPackage[ $name ][ $packageGroupPointers[ 'groupHash' ] ][ $packageGroupPointers[ 'dependencyHash' ] ];
356
+                foreach ( $packageGroup as $pkg ) {
357
+                    if ( $pkg instanceof AliasPackage && $pkg->getPrettyVersion() === VersionParser::DEFAULT_BRANCH_ALIAS ) {
358 358
                         $pkg = $pkg->getAliasOf();
359 359
                     }
360
-                    $this->removedVersionsByPackage[spl_object_hash($package)][$pkg->getVersion()] = $pkg->getPrettyVersion();
360
+                    $this->removedVersionsByPackage[ spl_object_hash( $package ) ][ $pkg->getVersion() ] = $pkg->getPrettyVersion();
361 361
                 }
362 362
             }
363 363
         }
364 364
 
365
-        if (isset($this->aliasesPerPackage[$package->id])) {
366
-            foreach ($this->aliasesPerPackage[$package->id] as $aliasPackage) {
367
-                unset($this->packagesToRemove[$aliasPackage->id]);
365
+        if ( isset( $this->aliasesPerPackage[ $package->id ] ) ) {
366
+            foreach ( $this->aliasesPerPackage[ $package->id ] as $aliasPackage ) {
367
+                unset( $this->packagesToRemove[ $aliasPackage->id ] );
368 368
 
369 369
                 // record all the versions of the package group so we can list them later in Problem output
370
-                foreach ($aliasPackage->getNames(false) as $name) {
371
-                    if (isset($packageIdenticalDefinitionLookup[$aliasPackage->id][$name])) {
372
-                        $packageGroupPointers = $packageIdenticalDefinitionLookup[$aliasPackage->id][$name];
373
-                        $packageGroup = $identicalDefinitionsPerPackage[$name][$packageGroupPointers['groupHash']][$packageGroupPointers['dependencyHash']];
374
-                        foreach ($packageGroup as $pkg) {
375
-                            if ($pkg instanceof AliasPackage && $pkg->getPrettyVersion() === VersionParser::DEFAULT_BRANCH_ALIAS) {
370
+                foreach ( $aliasPackage->getNames( false ) as $name ) {
371
+                    if ( isset( $packageIdenticalDefinitionLookup[ $aliasPackage->id ][ $name ] ) ) {
372
+                        $packageGroupPointers = $packageIdenticalDefinitionLookup[ $aliasPackage->id ][ $name ];
373
+                        $packageGroup = $identicalDefinitionsPerPackage[ $name ][ $packageGroupPointers[ 'groupHash' ] ][ $packageGroupPointers[ 'dependencyHash' ] ];
374
+                        foreach ( $packageGroup as $pkg ) {
375
+                            if ( $pkg instanceof AliasPackage && $pkg->getPrettyVersion() === VersionParser::DEFAULT_BRANCH_ALIAS ) {
376 376
                                 $pkg = $pkg->getAliasOf();
377 377
                             }
378
-                            $this->removedVersionsByPackage[spl_object_hash($aliasPackage)][$pkg->getVersion()] = $pkg->getPrettyVersion();
378
+                            $this->removedVersionsByPackage[ spl_object_hash( $aliasPackage ) ][ $pkg->getVersion() ] = $pkg->getPrettyVersion();
379 379
                         }
380 380
                     }
381 381
                 }
@@ -390,59 +390,59 @@  discard block
 block discarded – undo
390 390
      *
391 391
      * @return void
392 392
      */
393
-    private function optimizeImpossiblePackagesAway(Request $request, Pool $pool)
393
+    private function optimizeImpossiblePackagesAway( Request $request, Pool $pool )
394 394
     {
395
-        if (count($request->getLockedPackages()) === 0) {
395
+        if ( count( $request->getLockedPackages() ) === 0 ) {
396 396
             return;
397 397
         }
398 398
 
399 399
         $packageIndex = array();
400 400
 
401
-        foreach ($pool->getPackages() as $package) {
401
+        foreach ( $pool->getPackages() as $package ) {
402 402
             $id = $package->id;
403 403
 
404 404
             // Do not remove irremovable packages
405
-            if (isset($this->irremovablePackages[$id])) {
405
+            if ( isset( $this->irremovablePackages[ $id ] ) ) {
406 406
                 continue;
407 407
             }
408 408
             // Do not remove a package aliased by another package, nor aliases
409
-            if (isset($this->aliasesPerPackage[$id]) || $package instanceof AliasPackage) {
409
+            if ( isset( $this->aliasesPerPackage[ $id ] ) || $package instanceof AliasPackage ) {
410 410
                 continue;
411 411
             }
412 412
             // Do not remove locked packages
413
-            if ($request->isFixedPackage($package) || $request->isLockedPackage($package)) {
413
+            if ( $request->isFixedPackage( $package ) || $request->isLockedPackage( $package ) ) {
414 414
                 continue;
415 415
             }
416 416
 
417
-            $packageIndex[$package->getName()][$package->id] = $package;
417
+            $packageIndex[ $package->getName() ][ $package->id ] = $package;
418 418
         }
419 419
 
420
-        foreach ($request->getLockedPackages() as $package) {
420
+        foreach ( $request->getLockedPackages() as $package ) {
421 421
             // If this locked package is no longer required by root or anything in the pool, it may get uninstalled so do not apply its requirements
422 422
             // In a case where a requirement WERE to appear in the pool by a package that would not be used, it would've been unlocked and so not filtered still
423 423
             $isUnusedPackage = true;
424
-            foreach ($package->getNames(false) as $packageName) {
425
-                if (isset($this->requireConstraintsPerPackage[$packageName])) {
424
+            foreach ( $package->getNames( false ) as $packageName ) {
425
+                if ( isset( $this->requireConstraintsPerPackage[ $packageName ] ) ) {
426 426
                     $isUnusedPackage = false;
427 427
                     break;
428 428
                 }
429 429
             }
430 430
 
431
-            if ($isUnusedPackage) {
431
+            if ( $isUnusedPackage ) {
432 432
                 continue;
433 433
             }
434 434
 
435
-            foreach ($package->getRequires() as $link) {
435
+            foreach ( $package->getRequires() as $link ) {
436 436
                 $require = $link->getTarget();
437
-                if (!isset($packageIndex[$require])) {
437
+                if ( ! isset( $packageIndex[ $require ] ) ) {
438 438
                     continue;
439 439
                 }
440 440
 
441 441
                 $linkConstraint = $link->getConstraint();
442
-                foreach ($packageIndex[$require] as $id => $requiredPkg) {
443
-                    if (false === CompilingMatcher::match($linkConstraint, Constraint::OP_EQ, $requiredPkg->getVersion())) {
444
-                        $this->markPackageForRemoval($id);
445
-                        unset($packageIndex[$require][$id]);
442
+                foreach ( $packageIndex[ $require ] as $id => $requiredPkg ) {
443
+                    if ( false === CompilingMatcher::match( $linkConstraint, Constraint::OP_EQ, $requiredPkg->getVersion() ) ) {
444
+                        $this->markPackageForRemoval( $id );
445
+                        unset( $packageIndex[ $require ][ $id ] );
446 446
                     }
447 447
                 }
448 448
             }
Please login to merge, or discard this patch.
Braces   +11 added lines, -22 removed lines patch added patch discarded remove patch
@@ -26,8 +26,7 @@  discard block
 block discarded – undo
26 26
  *
27 27
  * @author Yanick Witschi <[email protected]>
28 28
  */
29
-class PoolOptimizer
30
-{
29
+class PoolOptimizer {
31 30
     /**
32 31
      * @var PolicyInterface
33 32
      */
@@ -63,16 +62,14 @@  discard block
 block discarded – undo
63 62
      */
64 63
     private $removedVersionsByPackage = array();
65 64
 
66
-    public function __construct(PolicyInterface $policy)
67
-    {
65
+    public function __construct(PolicyInterface $policy) {
68 66
         $this->policy = $policy;
69 67
     }
70 68
 
71 69
     /**
72 70
      * @return Pool
73 71
      */
74
-    public function optimize(Request $request, Pool $pool)
75
-    {
72
+    public function optimize(Request $request, Pool $pool) {
76 73
         $this->prepare($request, $pool);
77 74
 
78 75
         $this->optimizeByIdenticalDependencies($request, $pool);
@@ -99,8 +96,7 @@  discard block
 block discarded – undo
99 96
     /**
100 97
      * @return void
101 98
      */
102
-    private function prepare(Request $request, Pool $pool)
103
-    {
99
+    private function prepare(Request $request, Pool $pool) {
104 100
         $irremovablePackageConstraintGroups = array();
105 101
 
106 102
         // Mark fixed or locked packages as irremovable
@@ -155,8 +151,7 @@  discard block
 block discarded – undo
155 151
     /**
156 152
      * @return void
157 153
      */
158
-    private function markPackageIrremovable(BasePackage $package)
159
-    {
154
+    private function markPackageIrremovable(BasePackage $package) {
160 155
         $this->irremovablePackages[$package->id] = true;
161 156
         if ($package instanceof AliasPackage) {
162 157
             // recursing here so aliasesPerPackage for the aliasOf can be checked
@@ -173,8 +168,7 @@  discard block
 block discarded – undo
173 168
     /**
174 169
      * @return Pool Optimized pool
175 170
      */
176
-    private function applyRemovalsToPool(Pool $pool)
177
-    {
171
+    private function applyRemovalsToPool(Pool $pool) {
178 172
         $packages = array();
179 173
         $removedVersions = array();
180 174
         foreach ($pool->getPackages() as $package) {
@@ -193,8 +187,7 @@  discard block
 block discarded – undo
193 187
     /**
194 188
      * @return void
195 189
      */
196
-    private function optimizeByIdenticalDependencies(Request $request, Pool $pool)
197
-    {
190
+    private function optimizeByIdenticalDependencies(Request $request, Pool $pool) {
198 191
         $identicalDefinitionsPerPackage = array();
199 192
         $packageIdenticalDefinitionLookup = array();
200 193
 
@@ -279,8 +272,7 @@  discard block
 block discarded – undo
279 272
     /**
280 273
      * @return string
281 274
      */
282
-    private function calculateDependencyHash(BasePackage $package)
283
-    {
275
+    private function calculateDependencyHash(BasePackage $package) {
284 276
         $hash = '';
285 277
 
286 278
         $hashRelevantLinks = array(
@@ -323,8 +315,7 @@  discard block
 block discarded – undo
323 315
      * @param int $id
324 316
      * @return void
325 317
      */
326
-    private function markPackageForRemoval($id)
327
-    {
318
+    private function markPackageForRemoval($id) {
328 319
         // We are not allowed to remove packages if they have been marked as irremovable
329 320
         if (isset($this->irremovablePackages[$id])) {
330 321
             throw new \LogicException('Attempted removing a package which was previously marked irremovable');
@@ -338,8 +329,7 @@  discard block
 block discarded – undo
338 329
      * @param array<int, array<string, array{groupHash: string, dependencyHash: string}>> $packageIdenticalDefinitionLookup
339 330
      * @return void
340 331
      */
341
-    private function keepPackage(BasePackage $package, $identicalDefinitionsPerPackage, $packageIdenticalDefinitionLookup)
342
-    {
332
+    private function keepPackage(BasePackage $package, $identicalDefinitionsPerPackage, $packageIdenticalDefinitionLookup) {
343 333
         unset($this->packagesToRemove[$package->id]);
344 334
 
345 335
         if ($package instanceof AliasPackage) {
@@ -390,8 +380,7 @@  discard block
 block discarded – undo
390 380
      *
391 381
      * @return void
392 382
      */
393
-    private function optimizeImpossiblePackagesAway(Request $request, Pool $pool)
394
-    {
383
+    private function optimizeImpossiblePackagesAway(Request $request, Pool $pool) {
395 384
         if (count($request->getLockedPackages()) === 0) {
396 385
             return;
397 386
         }
Please login to merge, or discard this patch.
Filter/PlatformRequirementFilter/PlatformRequirementFilterInterface.php 3 patches
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -4,9 +4,9 @@
 block discarded – undo
4 4
 
5 5
 interface PlatformRequirementFilterInterface
6 6
 {
7
-    /**
8
-     * @param string $req
9
-     * @return bool
10
-     */
11
-    public function isIgnored($req);
7
+	/**
8
+	 * @param string $req
9
+	 * @return bool
10
+	 */
11
+	public function isIgnored($req);
12 12
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -8,5 +8,5 @@
 block discarded – undo
8 8
      * @param string $req
9 9
      * @return bool
10 10
      */
11
-    public function isIgnored($req);
11
+    public function isIgnored( $req );
12 12
 }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -2,8 +2,7 @@
 block discarded – undo
2 2
 
3 3
 namespace Composer\Filter\PlatformRequirementFilter;
4 4
 
5
-interface PlatformRequirementFilterInterface
6
-{
5
+interface PlatformRequirementFilterInterface {
7 6
     /**
8 7
      * @param string $req
9 8
      * @return bool
Please login to merge, or discard this patch.
Filter/PlatformRequirementFilter/IgnoreNothingPlatformRequirementFilter.php 3 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -4,12 +4,12 @@
 block discarded – undo
4 4
 
5 5
 final class IgnoreNothingPlatformRequirementFilter implements PlatformRequirementFilterInterface
6 6
 {
7
-    /**
8
-     * @param string $req
9
-     * @return false
10
-     */
11
-    public function isIgnored($req)
12
-    {
13
-        return false;
14
-    }
7
+	/**
8
+	 * @param string $req
9
+	 * @return false
10
+	 */
11
+	public function isIgnored($req)
12
+	{
13
+		return false;
14
+	}
15 15
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@
 block discarded – undo
8 8
      * @param string $req
9 9
      * @return false
10 10
      */
11
-    public function isIgnored($req)
11
+    public function isIgnored( $req )
12 12
     {
13 13
         return false;
14 14
     }
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -2,14 +2,12 @@
 block discarded – undo
2 2
 
3 3
 namespace Composer\Filter\PlatformRequirementFilter;
4 4
 
5
-final class IgnoreNothingPlatformRequirementFilter implements PlatformRequirementFilterInterface
6
-{
5
+final class IgnoreNothingPlatformRequirementFilter implements PlatformRequirementFilterInterface {
7 6
     /**
8 7
      * @param string $req
9 8
      * @return false
10 9
      */
11
-    public function isIgnored($req)
12
-    {
10
+    public function isIgnored($req) {
13 11
         return false;
14 12
     }
15 13
 }
Please login to merge, or discard this patch.