@@ -40,18 +40,18 @@ discard block |
||
40 | 40 | * @var array[] A map of handler class names to their integer priority and whether they are enabled by default. |
41 | 41 | */ |
42 | 42 | protected const injectableHandlersOrder = [ |
43 | - XmlToPh::class => [ 'position' => 0, 'default_enabled' => true ], |
|
44 | - Variables::class => [ 'position' => 1, 'default_enabled' => true ], |
|
45 | - TwigToPh::class => [ 'position' => 2, 'default_enabled' => true ], |
|
46 | - RubyOnRailsI18n::class => [ 'position' => 3, 'default_enabled' => true ], |
|
47 | - Snails::class => [ 'position' => 4, 'default_enabled' => true ], |
|
48 | - DoubleSquareBrackets::class => [ 'position' => 5, 'default_enabled' => true ], |
|
49 | - DollarCurlyBrackets::class => [ 'position' => 6, 'default_enabled' => true ], |
|
50 | - SingleCurlyBracketsToPh::class => [ 'position' => 7, 'default_enabled' => false ], // Disabled by default because it may conflict with other curly braces handlers |
|
51 | - ObjectiveCNSString::class => [ 'position' => 8, 'default_enabled' => true ], |
|
52 | - DoublePercentages::class => [ 'position' => 9, 'default_enabled' => true ], |
|
53 | - SquareSprintf::class => [ 'position' => 10, 'default_enabled' => true ], |
|
54 | - SprintfToPH::class => [ 'position' => 11, 'default_enabled' => true ], |
|
43 | + XmlToPh::class => ['position' => 0, 'default_enabled' => true], |
|
44 | + Variables::class => ['position' => 1, 'default_enabled' => true], |
|
45 | + TwigToPh::class => ['position' => 2, 'default_enabled' => true], |
|
46 | + RubyOnRailsI18n::class => ['position' => 3, 'default_enabled' => true], |
|
47 | + Snails::class => ['position' => 4, 'default_enabled' => true], |
|
48 | + DoubleSquareBrackets::class => ['position' => 5, 'default_enabled' => true], |
|
49 | + DollarCurlyBrackets::class => ['position' => 6, 'default_enabled' => true], |
|
50 | + SingleCurlyBracketsToPh::class => ['position' => 7, 'default_enabled' => false], // Disabled by default because it may conflict with other curly braces handlers |
|
51 | + ObjectiveCNSString::class => ['position' => 8, 'default_enabled' => true], |
|
52 | + DoublePercentages::class => ['position' => 9, 'default_enabled' => true], |
|
53 | + SquareSprintf::class => ['position' => 10, 'default_enabled' => true], |
|
54 | + SprintfToPH::class => ['position' => 11, 'default_enabled' => true], |
|
55 | 55 | ]; |
56 | 56 | |
57 | 57 | /** |
@@ -60,8 +60,8 @@ discard block |
||
60 | 60 | * @return array The array of handlers that are enabled by default. |
61 | 61 | */ |
62 | 62 | public static function getDefaultInjectedHandlers(): array { |
63 | - return array_filter( self::injectableHandlersOrder, function ( $settings ) { |
|
64 | - return $settings[ 'default_enabled' ]; |
|
63 | + return array_filter(self::injectableHandlersOrder, function($settings) { |
|
64 | + return $settings['default_enabled']; |
|
65 | 65 | } ); |
66 | 66 | } |
67 | 67 | |
@@ -84,13 +84,13 @@ discard block |
||
84 | 84 | * |
85 | 85 | * @param class-string[] $injectedHandlers An array of handler class names to be sorted. |
86 | 86 | */ |
87 | - public function __construct( array $injectedHandlers = [] ) { |
|
87 | + public function __construct(array $injectedHandlers = []) { |
|
88 | 88 | |
89 | 89 | // Start with the default order of handlers. |
90 | 90 | $this->defaultInjectedHandlers = self::injectableHandlersOrder; |
91 | 91 | |
92 | 92 | // Sort the final list of handlers according to their predefined execution order. |
93 | - $this->injectedHandlers = $this->quickSort( $injectedHandlers ); |
|
93 | + $this->injectedHandlers = $this->quickSort($injectedHandlers); |
|
94 | 94 | |
95 | 95 | } |
96 | 96 | |
@@ -105,16 +105,16 @@ discard block |
||
105 | 105 | * |
106 | 106 | * @return string[] The sorted list of handler class names based on their priorities. |
107 | 107 | */ |
108 | - private function quickSort( array $handlersList ): array { |
|
108 | + private function quickSort(array $handlersList): array { |
|
109 | 109 | // Filter the list to include only valid handlers. |
110 | - $filteredHandlers = array_filter( $handlersList, function ( $handler ) { |
|
111 | - return array_key_exists( $handler, $this->defaultInjectedHandlers ); |
|
110 | + $filteredHandlers = array_filter($handlersList, function($handler) { |
|
111 | + return array_key_exists($handler, $this->defaultInjectedHandlers); |
|
112 | 112 | } ); |
113 | 113 | |
114 | 114 | // Sort the handlers based on their priority using a custom comparison function. |
115 | - usort( $filteredHandlers, function ( $a, $b ) { |
|
115 | + usort($filteredHandlers, function($a, $b) { |
|
116 | 116 | // The spaceship operator (<=>) returns -1, 0, or 1, which is what usort expects. |
117 | - return $this->defaultInjectedHandlers[ $a ] <=> $this->defaultInjectedHandlers[ $b ]; |
|
117 | + return $this->defaultInjectedHandlers[$a] <=> $this->defaultInjectedHandlers[$b]; |
|
118 | 118 | } ); |
119 | 119 | |
120 | 120 | return $filteredHandlers; |