Skip to content

Commit

Permalink
Refactor how we generate the phpcs executable
Browse files Browse the repository at this point in the history
This is so we are consistent with the shelling out, without duplicating
the code.
  • Loading branch information
benmatselby committed Oct 14, 2023
1 parent a0c16d2 commit 82e5163
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions phpcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 82e5163

Please sign in to comment.