# frozen_string_literal: true

require "cc/engine/analyzers/php/parser"
require "cc/engine/analyzers/analyzer_base"
require "flay"
require "json"

module CC
  module Engine
    module Analyzers
      module Php
        class Main < CC::Engine::Analyzers::Base
          LANGUAGE = "php"
          PATTERNS = [
            "**/*.php",
          ].freeze
          DEFAULT_MASS_THRESHOLD = 28
          DEFAULT_FILTERS = [
            "(use ___)".freeze,
          ].freeze
          POINTS_PER_OVERAGE = 100_000

          def transform_sexp(sexp)
            sexp.flatter
          end

          def use_sexp_lines?
            false
          end

          private

          def process_file(path)
            code = File.binread(path)
            ast = php_parser.new(code, path).parse
            ast.syntax_tree&.to_sexp if ast
          end

          def php_parser
            ::CC::Engine::Analyzers::Php::Parser
          end

          def default_filters
            DEFAULT_FILTERS.map { |filter| Sexp::Matcher.parse filter }
          end
        end
      end
    end
  end
end

# frozen_string_literal: true

require "cc/engine/analyzers/php/parser"
require "cc/engine/analyzers/analyzer_base"
require "flay"
require "json"

module CC
  module Engine
    module Analyzers
      module Php
        class Main < CC::Engine::Analyzers::Base
          LANGUAGE = "php"
          PATTERNS = [
            "**/*.php",
          ].freeze
          DEFAULT_MASS_THRESHOLD = 28
          DEFAULT_FILTERS = [
            "(use ___)".freeze,
          ].freeze
          POINTS_PER_OVERAGE = 100_000

          def transform_sexp(sexp)
            sexp.flatter
          end

          private

          def process_file(path)
            code = File.binread(path)
            ast = php_parser.new(code, path).parse
            ast.syntax_tree&.to_sexp if ast
          end

          def php_parser
            ::CC::Engine::Analyzers::Php::Parser
          end

          def default_filters
            DEFAULT_FILTERS.map { |filter| Sexp::Matcher.parse filter }
          end
        end
      end
    end
  end
end

Use `SexpLines` for PHP parser
Use `SexpLines` for PHP parser

Since we're reverting back to the old PHP parser, we need to restore the
use of `SexpLines`.
