From 82e516331b03ed64122fbb9d9568ec1bf22c1790 Mon Sep 17 00:00:00 2001 From: Ben Selby Date: Sat, 14 Oct 2023 20:51:34 +0100 Subject: [PATCH] Refactor how we generate the phpcs executable This is so we are consistent with the shelling out, without duplicating the code. --- phpcs.py | 51 ++++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/phpcs.py b/phpcs.py index 1a8962c..2307a79 100644 --- a/phpcs.py +++ b/phpcs.py @@ -209,24 +209,7 @@ def execute(self, path): if pref.phpcs_sniffer_run != True: return - args = [] - - if ( - pref.phpcs_php_prefix_path != "" - and self.__class__.__name__ in pref.phpcs_commands_to_php_prefix - ): - args = [pref.phpcs_php_prefix_path] - - if pref.phpcs_executable_path != "": - application_path = pref.phpcs_executable_path - else: - application_path = "phpcs" - - if len(args) > 0: - args.append(application_path) - else: - args = [application_path] - + args = self.get_executable_args() args.append("--report=checkstyle") # Add the additional arguments from the settings file to the command @@ -248,6 +231,30 @@ def execute(self, path): args.append(target) self.parse_report(args) + def get_executable_args(self): + """ + Figure out how we are going to construct the executable path for phpcs + """ + args = [] + + if ( + pref.phpcs_php_prefix_path != "" + and self.__class__.__name__ in pref.phpcs_commands_to_php_prefix + ): + args = [pref.phpcs_php_prefix_path] + + if pref.phpcs_executable_path != "": + application_path = pref.phpcs_executable_path + else: + application_path = "phpcs" + + if len(args) > 0: + args.append(application_path) + else: + args = [application_path] + + return args + def parse_report(self, args): report = self.shell_out(args) debug_message(report) @@ -261,13 +268,7 @@ def parse_report(self, args): self.error_list.append(error) def get_standards_available(self): - if pref.phpcs_executable_path != "": - application_path = pref.phpcs_executable_path - else: - application_path = "phpcs" - - args = [] - args.append(application_path) + args = self.get_executable_args() args.append("-i") output = self.shell_out(args)