<commit_before>(* <NAME>
 *
 * Copyright (C) 2010 Facebook
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * version 2.1 as published by the Free Software Foundation, with the
 * special exception on linking described in file license.txt.
 * 
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the file
 * license.txt for more details.
 *)

open Common

open Ast_php

module E = Error_php
open Error_php

(*****************************************************************************)
(* Prelude *)
(*****************************************************************************)

(*
 * Structure similar to other layer generator.
 *)

(*****************************************************************************)
(* Types *)
(*****************************************************************************)

(* ugly: there is some duplication and coupling with the Error_php.error
 * type.
 *)
let properties = [
  "eUndefinedFunction",    "blue";
  "eUnableToDetermineDef", "blue2";

  "eTooManyArguments", "blue3";
  "eNotEnoughArguments", "blue4";

  "eTooManyArguments2", "blue3" ;
  "eTooFewArguments2",  "blue4" ;
  "eWrongKeywordArgument", "yellow";

  "eUseOfUndefinedVariable", "red" ;
  "eUnusedVariable", "purple";

  "eUseOfUndefinedMember", "cyan";
  "eUglyGlobalDynamic", "cyan";
]

(*****************************************************************************)
(* Code *)
(*****************************************************************************)

let info_of_error_and_kind err =

  let kind = 
    match err with
  | UndefinedFunction _ -> "eUndefinedFunction"
  | UnableToDetermineDef _ ->"eUnableToDetermineDef"

  | TooManyArguments _ ->"eTooManyArguments"
  | NotEnoughArguments _ ->"eNotEnoughArguments"

  | TooManyArguments2 _ ->"eTooManyArguments2"
  | TooFewArguments2  _ ->"eTooFewArguments2"
  | WrongKeywordArgument _ ->"eWrongKeywordArgument"

  | UseOfUndefinedVariable _ ->"eUseOfUndefinedVariable"
  | UnusedVariable _ ->"eUnusedVariable"

  | UseOfUndefinedMember _ ->"eUseOfUndefinedMember"
  | UglyGlobalDynamic _ -> "eUglyGlobalDynamic"
  in
  E.info_of_error err +> Common.fmap (fun info ->
    info, kind
  )

(*****************************************************************************)<commit_msg>layer_checker_php: refined layer for different kind of UnusedVariables errors (unused params vs unused variables etc)<commit_after>(* <NAME>
 *
 * Copyright (C) 2010 Facebook
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * version 2.1 as published by the Free Software Foundation, with the
 * special exception on linking described in file license.txt.
 * 
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the file
 * license.txt for more details.
 *)

open Common

open Ast_php

module E = Error_php
open Error_php

(*****************************************************************************)
(* Prelude *)
(*****************************************************************************)

(*
 * Structure similar to other layer generator.
 *)

(*****************************************************************************)
(* Types *)
(*****************************************************************************)

(* ugly: there is some duplication with Error_php.error
 * coupling: with the Error_php.error type 
 *)
let properties = [
  "eUndefinedFunction",    "blue";
  "eUnableToDetermineDef", "blue2";

  "eTooManyArguments", "blue3";
  "eNotEnoughArguments", "blue4";

  "eTooManyArguments2", "blue3" ;
  "eTooFewArguments2",  "blue4" ;
  "eWrongKeywordArgument", "yellow";

  "eUseOfUndefinedVariable", "red" ;

  "eUseOfUndefinedMember", "cyan";
  "eUglyGlobalDynamic", "cyan";
  "eWeirdForeachNoIteratorVar", "cyan";

  (* ugly: coupling with scope_code.ml *)
  "eUnusedVariable-Local", "purple";

  "eUnusedVariable-Global", "green";
  "eUnusedVariable-Local", "green";
  "eUnusedVariable-Param", "green";
  "eUnusedVariable-Static", "green";
  "eUnusedVariable-Class", "green";
  "eUnusedVariable-LocalExn", "green";
  "eUnusedVariable-LocalIterator", "green";
  "eUnusedVariable-ListBinded", "green";
  "eUnusedVariable-NoScope", "green";


]

(*****************************************************************************)
(* Code *)
(*****************************************************************************)

let info_of_error_and_kind err =

  let kind = 
    match err with
  | UndefinedFunction _ -> "eUndefinedFunction"
  | UnableToDetermineDef _ ->"eUnableToDetermineDef"

  | TooManyArguments _ ->"eTooManyArguments"
  | NotEnoughArguments _ ->"eNotEnoughArguments"

  | TooManyArguments2 _ ->"eTooManyArguments2"
  | TooFewArguments2  _ ->"eTooFewArguments2"
  | WrongKeywordArgument _ ->"eWrongKeywordArgument"

  | UseOfUndefinedVariable _ -> 
      "eUseOfUndefinedVariable"
  | UnusedVariable (_, scope) ->
      "eUnusedVariable-" ^ Scope_code.string_of_scope scope

  | UseOfUndefinedMember _ ->"eUseOfUndefinedMember"
  | UglyGlobalDynamic _ -> "eUglyGlobalDynamic"
  | WeirdForeachNoIteratorVar _ -> "eWeirdForeachNoIteratorVar"

  in
  E.info_of_error err +> Common.fmap (fun info ->
    info, kind
  )

(*****************************************************************************)
{'fraction_non_alphanumeric': 0.2815878079035974, 'fraction_numerical': 0.006025163919900762, 'mean_word_length': 5.65566037735849, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5316174', 'n_tokens_mistral': 1594, 'n_tokens_neox': 1479, 'n_words': 392}