33
44use Payum \Core \Extension \StorageExtension ;
55use Payum \Core \Gateway ;
6- use Payum \Core \Registry \ RegistryInterface ;
6+ use Payum \Core \Payum ;
77use Payum \Core \Storage \AbstractStorage ;
8+ use Symfony \Component \Console \Attribute \AsCommand ;
89use Symfony \Component \Console \Command \Command ;
910use Symfony \Component \Console \Input \InputArgument ;
1011use Symfony \Component \Console \Input \InputInterface ;
1112use Symfony \Component \Console \Input \InputOption ;
1213use Symfony \Component \Console \Output \OutputInterface ;
1314use Symfony \Component \Console \Question \ChoiceQuestion ;
14- use Symfony \Component \DependencyInjection \ContainerAwareInterface ;
15- use Symfony \Component \DependencyInjection \ContainerAwareTrait ;
1615
17- class DebugGatewayCommand extends Command implements ContainerAwareInterface
16+ #[AsCommand(name: 'debug:payum:gateway ' , aliases: ['payum:gateway:debug ' ])]
17+ class DebugGatewayCommand extends Command
1818{
19- use ContainerAwareTrait;
20-
2119 protected static $ defaultName = 'debug:payum:gateway ' ;
2220
21+ protected Payum $ payum ;
22+
23+ public function __construct (Payum $ payum )
24+ {
25+ $ this ->payum = $ payum ;
26+ parent ::__construct ();
27+ }
28+
2329 /**
2430 * {@inheritDoc}
2531 */
@@ -35,15 +41,16 @@ protected function configure(): void
3541
3642 /**
3743 * {@inheritDoc}
44+ * @throws \ReflectionException
3845 */
3946 protected function execute (InputInterface $ input , OutputInterface $ output ): int
4047 {
41- $ gateways = $ this ->getPayum () ->getGateways ();
48+ $ gateways = $ this ->payum ->getGateways ();
4249
4350 if ($ gatewayName = $ input ->getArgument ('gateway-name ' )) {
4451 $ gatewayName = $ this ->findProperGatewayName ($ input , $ output , $ gateways , $ gatewayName );
4552 $ gateways = array (
46- $ gatewayName => $ this ->getPayum () ->getGateway ($ gatewayName ),
53+ $ gatewayName => $ this ->payum ->getGateway ($ gatewayName ),
4754 );
4855 }
4956
@@ -55,7 +62,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5562 $ output ->writeln ('' );
5663 $ output ->writeln (sprintf ('%s (%s): ' , $ name , get_class ($ gateway )));
5764
58- if (false == $ gateway instanceof Gateway) {
65+ if (false === $ gateway instanceof Gateway) {
5966 continue ;
6067 }
6168
@@ -123,12 +130,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
123130 return 0 ;
124131 }
125132
126- /**
127- * @param \ReflectionMethod $reflectionMethod
128- *
129- * @return array
130- */
131- protected function getMethodCode (\ReflectionMethod $ reflectionMethod )
133+ protected function getMethodCode (\ReflectionMethod $ reflectionMethod ): array
132134 {
133135 $ file = file ($ reflectionMethod ->getFileName ());
134136
@@ -140,15 +142,7 @@ protected function getMethodCode(\ReflectionMethod $reflectionMethod)
140142 return array_values ($ methodCodeLines );
141143 }
142144
143- /**
144- * @return RegistryInterface
145- */
146- protected function getPayum ()
147- {
148- return $ this ->container ->get ('payum ' );
149- }
150-
151- private function findProperGatewayName (InputInterface $ input , OutputInterface $ output , $ gateways , $ name )
145+ private function findProperGatewayName (InputInterface $ input , OutputInterface $ output , array $ gateways , string $ name )
152146 {
153147 $ helperSet = $ this ->getHelperSet ();
154148 if (!$ helperSet ->has ('question ' ) || isset ($ gateways [$ name ]) || !$ input ->isInteractive ()) {
@@ -165,14 +159,14 @@ private function findProperGatewayName(InputInterface $input, OutputInterface $o
165159 return $ this ->getHelper ('question ' )->ask ($ input , $ output , $ question );
166160 }
167161
168- private function findGatewaysContaining ($ gateways , $ name )
162+ private function findGatewaysContaining (array $ gateways , string $ name ): array
169163 {
170164 $ threshold = 1e3 ;
171165 $ foundGateways = array ();
172166
173167 foreach ($ gateways as $ gatewayName => $ gateway ) {
174168 $ lev = levenshtein ($ name , $ gatewayName );
175- if ($ lev <= strlen ($ name ) / 3 || false !== strpos ($ gatewayName , $ name )) {
169+ if ($ lev <= strlen ($ name ) / 3 || str_contains ($ gatewayName , $ name )) {
176170 $ foundGateways [$ gatewayName ] = isset ($ foundGateways [$ gatewayName ]) ? $ foundGateways [$ gateway ] - $ lev : $ lev ;
177171 }
178172 }
0 commit comments