require 'pluginscan/reports/issues_report/issues_scanner/file_issues_scanner' require 'pluginscan/reports/issues_report/issues_scanner/line_issues_scanner' require 'pluginscan/reports/issues_report/issues_scanner/utf8_checker' require 'pluginscan/reports/issues_report/issues_models/check_findings' require 'pluginscan/reports/issues_report/issues_models/issues' module Pluginscan class IssuesScanner def initialize(checks) file_issues_scanner = FileIssuesScanner.new(checks) @file_scanner = FileScanner.new(file_issues_scanner) end def scan(files) issues = scan_files(files) Issues.new(issues) end private def scan_files(file_paths) file_paths.inject({}) do |issues, file_path| issues.merge file_path => scan_file(file_path) end end def scan_file(file_path) file_contents = File.read(file_path) @file_scanner.scan(file_contents) end end # Responsible for checking that a file's contents is valid # and if so, running an issues scan on it class FileScanner def initialize(issues_scanner) @issues_scanner = issues_scanner end def scan(file_contents) # Check file contents are valid UTF-8 to avoid exceptions later invalid_utf8 = UTF8Checker.new.check(file_contents) return Array(invalid_utf8) if invalid_utf8 @issues_scanner.scan(file_contents) end end end