<commit_before><?php

namespace Core\Element;

use Core\Database\Database;

class Element{
	
	protected $element;
	protected $db;
	
	public function __construct(Database $db){
		$this->db = $db;
		if(is_null($this->element)){
			$parts = explode('\\', get_class($this));
			$class_name = end($parts); //Récupère dernier élément du tableau
			$this->element = strtolower(str_replace('Element', '', $class_name . 's')); //On met en minuscule et on enlève le Element à la fin
		}
	}
	
	public function query($statement, $attr = null, $one = false){
		if($attr)
			return $this->db->prepare($statement, $attr, strrev(preg_replace(strrev("/Element/"),strrev('Entity'),strrev(str_replace('Element\\', 'Element\Entity\\', get_class($this))),1)), $one);
		else
			return $this->db->query($statement, strrev(preg_replace(strrev("/Element/"),strrev('Entity'),strrev(str_replace('Element\\', 'Element\Entity\\', get_class($this))),1)), $one);
	}
	
	//Pour le reste des query comme count par exemple, on utilise la méthode habituelle : $this->db->count
	
	public function all(){
		return $this->query('SELECT * FROM ' . PREFIX . $this->element);
	}
	
	public function find($id){
		return $this->query('SELECT * FROM ' . PREFIX . $this->element . ' WHERE id = ?', [$id], true);
	}
	
	public function strclean($string){
		$chars = array(
			'À' => 'a', 'Á' => 'a', 'Â' => 'a', 'Ä' => 'a', 'à' => 'a', 'á' => 'a', 'â' => 'a', 'ä' => 'a', '@' => 'a',
			'È' => 'e', 'É' => 'e', 'Ê' => 'e', 'Ë' => 'e', 'è' => 'e', 'é' => 'e', 'ê' => 'e', 'ë' => 'e', '€' => 'e',
			'Ì' => 'i', 'Í' => 'i', 'Î' => 'i', 'Ï' => 'i', 'ì' => 'i', 'í' => 'i', 'î' => 'i', 'ï' => 'i',
			'Ò' => 'o', 'Ó' => 'o', 'Ô' => 'o', 'Ö' => 'o', 'ò' => 'o', 'ó' => 'o', 'ô' => 'o', 'ö' => 'o',
			'Ù' => 'u', 'Ú' => 'u', 'Û' => 'u', 'Ü' => 'u', 'ù' => 'u', 'ú' => 'u', 'û' => 'u', 'ü' => 'u', 'µ' => 'u',
			'Œ' => 'oe', 'œ' => 'oe',
			'$' => 's');

		$string = strtr($string, $chars);
		$string = preg_replace('#[^A-Za-z0-9]+#', '-', $string);
		$string = trim($string, '-');
		$string = strtolower($string);

		return $string;
    }
	
}<commit_msg>Update Element.php<commit_after><?php

namespace Core\Element;

use Core\Database\Database;

class Element{
	
	protected $element;
	protected $db;
	
	private $entity;
	
	public function __construct($entity, Database $db){
		$this->db = $db;
		if(is_null($this->element)){
			$parts = explode('\\', get_class($this));
			$class_name = end($parts); //Récupère dernier élément du tableau
			$this->element = strtolower(str_replace('Element', '', $class_name . 's')); //On met en minuscule et on enlève le Element à la fin
		}
		$this->entity = $entity;
	}
	
	public function query($statement, $attr = null, $one = false){
		$entity = ($this->entity === true) ? strrev(preg_replace(strrev("/Element/"),strrev('Entity'),strrev(str_replace('Element\\', 'Element\Entity\\', get_class($this))),1)) : null;
		if($attr)
			return $this->db->prepare($statement, $attr, $entity, $one);
		else
			return $this->db->query($statement, $entity, $one);
	}
	
	public function count($statement){
		return $this->db->count($statement);
	}
	
	public function all(){
		return $this->query('SELECT * FROM ' . PREFIX . $this->element);
	}
	
	public function find($id){
		return $this->query('SELECT * FROM ' . PREFIX . $this->element . ' WHERE id = ?', [$id], true);
	}
	
	public function strclean($string){
		$chars = array(
			'À' => 'a', 'Á' => 'a', 'Â' => 'a', 'Ä' => 'a', 'à' => 'a', 'á' => 'a', 'â' => 'a', 'ä' => 'a', '@' => 'a',
			'È' => 'e', 'É' => 'e', 'Ê' => 'e', 'Ë' => 'e', 'è' => 'e', 'é' => 'e', 'ê' => 'e', 'ë' => 'e', '€' => 'e',
			'Ì' => 'i', 'Í' => 'i', 'Î' => 'i', 'Ï' => 'i', 'ì' => 'i', 'í' => 'i', 'î' => 'i', 'ï' => 'i',
			'Ò' => 'o', 'Ó' => 'o', 'Ô' => 'o', 'Ö' => 'o', 'ò' => 'o', 'ó' => 'o', 'ô' => 'o', 'ö' => 'o',
			'Ù' => 'u', 'Ú' => 'u', 'Û' => 'u', 'Ü' => 'u', 'ù' => 'u', 'ú' => 'u', 'û' => 'u', 'ü' => 'u', 'µ' => 'u',
			'Œ' => 'oe', 'œ' => 'oe',
			'$' => 's');

		$string = strtr($string, $chars);
		$string = preg_replace('#[^A-Za-z0-9]+#', '-', $string);
		$string = trim($string, '-');
		$string = strtolower($string);

		return $string;
    }
	
	protected function findType($id, $other_type = 'permalink'){
		if(ctype_digit($id))
			return 'id';
		else
			return $other_type;
	}
	
}
{'fraction_non_alphanumeric': 0.29460966542750927, 'fraction_numerical': 0.0016263940520446097, 'mean_word_length': 3.7203947368421053, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 123, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3676891', 'n_tokens_mistral': 1852, 'n_tokens_neox': 1746, 'n_words': 426}