Skip to content

Commit 5496d99

Browse files
committed
[UPD] update translation for vnumber
1 parent 89802e5 commit 5496d99

File tree

5 files changed

+100
-46
lines changed

5 files changed

+100
-46
lines changed

lang/fr/language.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
<?php
22
$language=[
3-
"`%s` should have minimum of `%s` caracters"=>"`%s` doit avoir un minimum de `%s` caracteres",
4-
"`%s` should have maximum of `%s` caracters"=>"`%s` doit avoir un maximum de `%s` caracteres",
3+
"`%s` should have minimum of `%s` characters"=>"`%s` doit avoir un minimum de `%s` caractèress",
4+
"`%s` should have maximum of `%s` characters"=>"`%s` doit avoir un maximum de `%s` caractèress",
55
"`%s` this should be an email"=>"`%s` doit etre un email",
66
"`%s` this should be a link(url)"=>"`%s` doit avoir un lien(url) ",
77
"`%s` should match %s"=>"`%s` doit correpondre a `%s`",
88
"`%s` is required"=>"`%s` est obligatoire",
9-
"`%s` should be a string"=>"`%s` doit est une chaine de caractere",
9+
"`%s` should be a string"=>"`%s` doit est une chaine de caractères",
10+
"`%s` should be greater than `%s`"=>"`%s` devrait être supérieur à `%s`",
11+
"`%s` should be less than `%s`"=>"`%s` devrait être inférieur à `%s`",
12+
"`%s` should be a positive number"=>"`%s` devrait être un nombre positif",
13+
"`%s` is unknow"=>"`%s` devrait être inférieur à `%s`",
14+
"`%s` should be less than `%s`"=>"`%s` devrait être inférieur à `%s`",
15+
"`%s` should be less than `%s`"=>"`%s` devrait être inférieur à `%s`",
1016
];

src/VNumber.php

Lines changed: 59 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
class VNumber {
1717
//put your code here
1818
private $string_value;
19-
private $string_item;
20-
private $source_data;
21-
private $_errors;
22-
private $_min;
23-
private $_max;
19+
private string $string_item;
20+
private array $source_data;
21+
private array $_errors;
22+
private int $_min;
23+
private int $_max;
2424

2525
function __construct(array $source,string $string_item) {
2626
$this->source_data=$source;
@@ -30,82 +30,120 @@ function __construct(array $source,string $string_item) {
3030
$this->string_value=$source[$string_item];
3131
}
3232
}
33-
function min(int $min_values){
33+
34+
/**
35+
* @param int $min_values
36+
* @return $this
37+
*/
38+
function min(int $min_values): VNumber
39+
{
3440
if ((int) $this->string_value < $min_values) {
3541
$message=[
3642
"type"=>"number.min",
37-
"message"=> "`{$this->string_item}` should be greater than `{$min_values}`",
43+
"message"=> i18n::translate("`%s` should be greater than `%s`",[$this->string_item,$min_values]),
3844
"label"=>$this->string_item,
3945
"limit"=>$min_values
4046
];
4147
$this->addError($message);
4248
}
4349
return $this;
4450
}
45-
function max(int $min_values){
51+
52+
/**
53+
* @param int $min_values
54+
* @return $this
55+
*/
56+
function max(int $min_values): VNumber
57+
{
4658
if ((int) $this->string_value > $min_values) {
4759
$message=[
4860
"type"=>"number.max",
49-
"message"=> "`{$this->string_item}` should be less than `{$min_values}`",
61+
"message"=> i18n::translate("`%s` should be less than `%s`",[$this->string_item,$min_values]),
5062
"label"=>$this->string_item,
5163
"limit"=>$min_values
5264
];
5365
$this->addError($message);
5466
}
5567
return $this;
5668
}
57-
function positive(int $min_values){
69+
70+
/**
71+
* @param int $min_values
72+
* @return $this
73+
*/
74+
function positive(int $min_values): VNumber
75+
{
5876
if ((int) $this->string_value < 0) {
5977
$message=[
6078
"type"=>"number.positive",
61-
"message"=> "`{$this->string_item}` should be a positive number",
79+
"message"=> i18n::translate("`%s` should be a positive number",[$this->string_item]),
6280
"label"=>$this->string_item,
6381
"limit"=>1
6482
];
6583
$this->addError($message);
6684
}
6785
return $this;
6886
}
69-
function required(){
87+
88+
/**
89+
* @return $this
90+
*/
91+
function required(): VNumber
92+
{
7093
$required_value= trim($this->string_value);
7194
if (empty($required_value)) {
7295
$message = [
7396
"type"=> "any.required",
74-
"message" => "`{$this->string_item}` is required",
97+
"message" => i18n::translate("`%s` is required",[$this->string_item]),
7598
"label" => $this->string_item,
7699
];
77100
$this->addError($message);
78101
}
79102
return $this;
80103
}
81-
//
82-
private function checkExist(string $itemKey=null){
83-
$item_to_check=$itemKey?$itemKey:$this->string_item;
104+
105+
/**
106+
* @param string|null $itemKey
107+
* @return bool
108+
*/
109+
private function checkExist(string $itemKey=null): bool
110+
{
111+
$item_to_check=!$itemKey?$this->string_item:$itemKey;
84112
$regex_string="#[a-zA-Z]#";
85113
$status_key_exist=true;
86114
if (!isset($this->source_data[$item_to_check])) {
87115
$message = [
88116
"type"=> "any.unknow",
89-
"message" => "`{$item_to_check}` is unknow",
117+
"message" => i18n::translate("`%s` is unknow",[$item_to_check]),
90118
"label" => $item_to_check,
91119
];
92120
$this->addError($message);
93121
$status_key_exist=false;
94122
}else if (preg_match($regex_string,trim($this->source_data[$item_to_check])) || !is_integer($this->source_data[$item_to_check])) {
95123
$message = [
96124
"type"=> "number.unknow",
97-
"message" => "`{$item_to_check}` should be a number",
125+
"message" => i18n::translate("`%s` should be a number",[$item_to_check]),
98126
"label" => $item_to_check,
99127
];
100128
$this->addError($message);
101129
$status_key_exist=false;
102130
}
103131
return $status_key_exist;
104132
}
105-
private function addError(array $value){
106-
return $this->_errors[]=$value;
133+
134+
/**
135+
* @param array $value
136+
*/
137+
private function addError(array $value): void
138+
{
139+
$this->_errors[] = $value;
107140
}
108-
function check(){
141+
142+
/**
143+
* @return array
144+
*/
145+
function check(): array
146+
{
109147
return $this->_errors;
110148
}
111149
}

src/VString.php

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@
1313
*/
1414
class VString {
1515
private $string_value;
16-
private $string_item;
17-
private $source_data;
18-
private $_errors;
19-
private $_min;
20-
private $_max;
16+
private ?string $string_item;
17+
private array $source_data=[];
18+
private array $_errors=[];
19+
private int $_min=0;
20+
private int $_max=0;
21+
2122
/**
22-
*
23+
*
2324
* @param array $source
24-
* @param string $string_item
25-
* @param string $stringValue
25+
* @param string|null $string_item
2626
*/
2727
function __construct(array $source,string $string_item=null) {
2828
$this->string_item=$string_item;
@@ -38,12 +38,13 @@ function __construct(array $source,string $string_item=null) {
3838
* @param int $rule_values
3939
* @return $this
4040
*/
41-
function min(int $rule_values=0){
41+
function min(int $rule_values=0): VString
42+
{
4243
$min=is_integer($rule_values)? ((int)$rule_values>0?(int)$rule_values:0):0;
4344
if (strlen($this->string_value) < $min) {
4445
$message=[
4546
"type"=>"string.min",
46-
"message"=> i18n::translate("`%s` should have minimum of `%s` caracters",[$this->string_item,$min]),
47+
"message"=> i18n::translate("`%s` should have minimum of `%s` characters",[$this->string_item,$min]),
4748
"label"=>$this->string_item,
4849
"limit"=>$min
4950
];
@@ -56,13 +57,14 @@ function min(int $rule_values=0){
5657
* @param int $rule_values
5758
* @return $this
5859
*/
59-
function max(int $rule_values=1){
60+
function max(int $rule_values=1): VString
61+
{
6062
$max = is_integer($rule_values) ? ((int)$rule_values > 0 ? (int)$rule_values : 0):0;
6163
$this->_max=$max;
6264
if (strlen($this->string_value) > $max) {
6365
$message = [
6466
"type" => "string.max",
65-
"message" => i18n::translate("`%s` should have maximum of `%s` caracters",[$this->string_item,$max]),
67+
"message" => i18n::translate("`%s` should have maximum of `%s` characters",[$this->string_item,$max]),
6668
"label" => $this->string_item,
6769
"limit" => $max
6870
];
@@ -74,7 +76,8 @@ function max(int $rule_values=1){
7476
*
7577
* @return $this
7678
*/
77-
function email(){
79+
function email(): VString
80+
{
7881
if (!filter_var($this->string_value, FILTER_VALIDATE_EMAIL)) {
7982
$message = [
8083
"type" => "string.email",
@@ -89,7 +92,8 @@ function email(){
8992
*
9093
* @return $this
9194
*/
92-
function url(){
95+
function url(): VString
96+
{
9397
if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i", $this->string_value)) {
9498
$message = [
9599
"type" => "string.url",
@@ -117,7 +121,12 @@ function match(string $key_tomatch){
117121
}
118122
return $this;
119123
}
120-
function required(){
124+
125+
/**
126+
* @return $this
127+
*/
128+
function required(): VString
129+
{
121130
$required_value= trim($this->string_value);
122131
if (empty($required_value)) {
123132
$message = [
@@ -141,7 +150,7 @@ private function checkExist(string $itemKey=null){
141150
if (!isset($this->source_data[$item_to_check])) {
142151
$message = [
143152
"type"=> "any.unknow",
144-
"message" => "`{$item_to_check}` is unknow",
153+
"message" => i18n::translate("`%s` is unknow",[$item_to_check]),
145154
"label" => $item_to_check,
146155
];
147156
$this->addError($message);
@@ -159,10 +168,11 @@ private function checkExist(string $itemKey=null){
159168
}/**
160169
*
161170
* @param array $value
162-
* @return type
163-
*/
164-
private function addError(array $value){
165-
return $this->_errors[]=$value;
171+
* @return void
172+
*/
173+
private function addError(array $value): void
174+
{
175+
$this->_errors[] = $value;
166176
}/**
167177
*
168178
* @return type
File renamed without changes.

test/index.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"date_created"=>"2021-05-23"
1717
];
1818
$valid=new Validate($source);
19-
include "./test/string.php";
20-
// include "./test/number.php";
19+
// include "./test/string.php";
20+
include "./test/number.php";
2121
// include "./test/boolean.php";
2222
// include "./test/date.php";

0 commit comments

Comments
 (0)