Issues (22)

src/Tafqeet.php (7 issues)

Severity
1
<?php
2
3
	namespace Alkoumi\LaravelArabicTafqeet;
4
5
	use Alkoumi\LaravelArabicTafqeet\Helpers\Calculators;
6
	use Alkoumi\LaravelArabicTafqeet\Helpers\Handler;
7
	use Alkoumi\LaravelArabicTafqeet\Helpers\Validation;
8
	use Alkoumi\LaravelArabicTafqeet\Helpers\App;
9
10
	class Tafqeet
11
	{
12
		use Calculators,Handler,Validation,App;
13
14
		public $config = [
15
16
			'connection_tool' => ' و',
17
18
			'default_currency' => 'sar',
19
20
			'starter' => 'فقط',
21
22
			'end' => 'لا غير',
23
24
			'currencies' => [
25
				'sar' => [
26
					'main1' => 'ريال',
27
					'main2' => 'ريالاً',
28
					'single' => 'هللة',
29
					'multi' => 'هللات'
30
				],
31
32
				'egp' => [
33
					'main1' => 'جنيه',
34
					'main2' => 'جنيهًا',
35
					'single' => 'قرش',
36
					'multi' => 'قروش'
37
				],
38
39
				'dzd' => [
40
					'main1' => 'دينار',
41
					'main2' => 'دينارًا',
42
					'single' => 'سنتيم',
43
					'multi' => 'سنتيمات'
44
				],
45
46
				'aed' => [
47
					'main1' => 'درهم',
48
					'main2' => 'درهمًا',
49
					'single' => 'فلس',
50
					'multi' => 'فلسات'
51
				],
52
53
				'kwd' => [
54
					'main1' => 'دينار',
55
					'main2' => 'دينارًا',
56
					'single' => 'فلس',
57
					'multi' => 'فلسات'
58
				],
59
60
				'bhd' => [
61
					'main1' => 'دينار',
62
					'main2' => 'دينارًا',
63
					'single' => 'فلس',
64
					'multi' => 'فلسات'
65
				],
66
67
				'iqd' => [
68
					'main1' => 'دينار',
69
					'main2' => 'دينارًا',
70
					'single' => 'فلس',
71
					'multi' => 'فلسات'
72
				],
73
				'lbp' => [
74
					'main1' => 'ليرة',
75
					'main2' => 'ليرة',
76
					'single' => 'قرش',
77
					'multi' => 'قروش'
78
				],
79
				'yer' => [
80
					'main1' => 'ريال',
81
					'main2' => 'ريالًا',
82
					'single' => 'فلس',
83
					'multi' => 'فلسات'
84
				],
85
86
				'jod' => [
87
					'main1' => 'دينار',
88
					'main2' => 'دينارًا',
89
					'single' => 'قرش',
90
					'multi' => 'قروش'
91
				],
92
93
				'usd' => [
94
					'main1' => 'دولار',
95
					'main2' => 'دولاراً',
96
					'single' => 'سنت',
97
					'multi' => 'سنت'
98
				],
99
                'sdg' => [
100
                    'main1' => 'قرش',
101
                    'main2' => 'قرشاً',
102
                    'single' => 'قرش',
103
                    'multi' => 'قروش'
104
                ],
105
                'mad' => [
106
                    'main1' => 'درهم',
107
                    'main2' => 'درهمًا',
108
                    'single' => 'سنتيم',
109
                    'multi' => 'سنتيمات'
110
                ],
111
                'tnd' => [
112
                    'main1' => 'دينار',
113
                    'main2' => 'دينارًا',
114
                    'single' => 'مليم',
115
                    'multi' => 'مليمات'
116
                ],
117
                'qar' => [
118
                    'main1' => 'ريال',
119
                    'main2' => 'ريالًا',
120
                    'single' => 'درهم',
121
                    'multi' => 'دراهم'
122
                ],
123
                'omr' => [
124
                    'main1' => 'ريال',
125
                    'main2' => 'ريالًا',
126
                    'single' => 'بيسة',
127
                    'multi' => 'بيسات'
128
                ],
129
130
            ],
131
132
		];
133
		/*
134
		 *  parsed number
135
		 * */
136
		public $after_comma_sum;
137
138
		/*
139
		 * array of numbers after split process
140
		 * */
141
		private $parsed_number;
0 ignored issues
show
The private property $parsed_number is not used, and could be removed.
Loading history...
142
143
		/*
144
		 * all number array
145
		 * all array count
146
		 * */
147
		private $parsed_number_array = [];
0 ignored issues
show
The private property $parsed_number_array is not used, and could be removed.
Loading history...
148
		private $all_numbers_len;
0 ignored issues
show
The private property $all_numbers_len is not used, and could be removed.
Loading history...
149
150
		/*
151
		 * before comma number array
152
		 * before comma array count
153
		 * */
154
		private $all_numbers_array;
0 ignored issues
show
The private property $all_numbers_array is not used, and could be removed.
Loading history...
155
		private $before_comma_len;
0 ignored issues
show
The private property $before_comma_len is not used, and could be removed.
Loading history...
156
157
		/*
158
		 * after comma number array
159
		 * after comma array count
160
		 * */
161
		private $before_comma_array;
0 ignored issues
show
The private property $before_comma_array is not used, and could be removed.
Loading history...
162
		private $after_comma_len;
163
		private $after_comma_array;
0 ignored issues
show
The private property $after_comma_array is not used, and could be removed.
Loading history...
164
165
		/*
166
		 * result before and after comma
167
		 *
168
		 * */
169
        public $result_before_comma;
170
        public $result_after_comma;
171
172
		private $is_main1_currency = true;
173
174
		/**
175
		 * @param int $amount
176
		 * @param string $currency
177
		 *
178
		 * @return mixed
179
		 */
180
		public static function inArabic($amount = 0,$currency = 'sar')
181
		{
182
			return (new self)->setAmount($amount)->initValidation()->prepare()->run()->result($currency);
183
		}
184
185
		/**
186
		 * @param string $currency
187
		 *
188
		 * @return mixed
189
		 */
190
		public function result($currency = 'sar')
191
		{
192
			$result = $this->config['starter'].' ';
193
194
			if ($this->is_main1_currency){
195
				$result .= $this->result_before_comma.' '.$this->config['currencies'][$currency]['main1'];
196
197
			}else{
198
				$result .= $this->result_before_comma.' '.$this->config['currencies'][$currency]['main2'];
199
200
			}
201
			if ($this->after_comma_len >= 1 && $this->after_comma_sum != 00){
202
				if (in_array($this->after_comma_sum,[
203
					3,4,5,6,7,8,9,10
204
				])){
205
					$result .= $this->config['connection_tool'].$this->result_after_comma.' '.
206
						$this->config['currencies'][$currency]['multi'];
207
				}else{
208
					$result .= $this->config['connection_tool'].$this->result_after_comma.' '.
209
						$this->config['currencies'][$currency]['single'];
210
				}
211
			}
212
			$result .= ' '.$this->config['end'];
213
214
			return str_replace('  ',' ',$result);
215
		}
216
217
		/**
218
		 * @return $this
219
		 */
220
		public function run()
221
		{
222
			$this->result_before_comma = $this->runBeforeComma();
223
			$this->result_after_comma = $this->runAfterComma();
224
			return $this;
225
		}
226
227
		/**
228
		 * @return $this
229
		 */
230
		public function prepare()
231
		{
232
			$this->split_parsed_number_to_two_number_depend_on_comma()->split_numbers_before_comma_to_array()->split_numbers_after_comma_to_array();
233
			return $this;
234
		}
235
236
	}
237