| 
									
										
										
										
											2023-07-03 00:08:14 -03:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-15 16:02:42 +02:00
										 |  |  | /* | 
					
						
							|  |  |  |  * IntervalException.php | 
					
						
							| 
									
										
										
										
											2023-10-29 17:41:14 +01:00
										 |  |  |  * Copyright (c) 2023 james@firefly-iii.org | 
					
						
							| 
									
										
										
										
											2023-07-04 06:23:59 -03:00
										 |  |  |  * | 
					
						
							|  |  |  |  * This file is part of Firefly III (https://github.com/firefly-iii). | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software: you can redistribute it and/or modify | 
					
						
							|  |  |  |  * it under the terms of the GNU Affero General Public License as | 
					
						
							|  |  |  |  * published by the Free Software Foundation, either version 3 of the | 
					
						
							|  |  |  |  * License, or (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program 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 | 
					
						
							|  |  |  |  * GNU Affero General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU Affero General Public License | 
					
						
							|  |  |  |  * along with this program.  If not, see <https://www.gnu.org/licenses/>. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-15 16:02:42 +02:00
										 |  |  | declare(strict_types=1); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-29 17:41:14 +01:00
										 |  |  | namespace FireflyIII\Exceptions; | 
					
						
							| 
									
										
										
										
											2023-07-03 00:08:14 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | use FireflyIII\Support\Calendar\Periodicity; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-04 13:29:19 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Class IntervalException | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2023-12-20 19:35:52 +01:00
										 |  |  | final class IntervalException extends \Exception | 
					
						
							| 
									
										
										
										
											2023-07-03 00:08:14 -03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2023-10-30 19:49:40 +01:00
										 |  |  |     public array       $availableIntervals; | 
					
						
							|  |  |  |     public Periodicity $periodicity; | 
					
						
							| 
									
										
										
										
											2023-12-20 19:35:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-05 19:41:37 +01:00
										 |  |  |     /** @var mixed */ | 
					
						
							| 
									
										
										
										
											2023-11-04 14:09:51 +01:00
										 |  |  |     protected $message = 'The periodicity %s is unknown. Choose one of available periodicity: %s'; | 
					
						
							| 
									
										
										
										
											2023-10-29 17:41:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-20 19:35:52 +01:00
										 |  |  |     public function __construct(string $message = '', int $code = 0, ?\Throwable $previous = null) | 
					
						
							| 
									
										
										
										
											2023-10-29 17:41:14 +01:00
										 |  |  |     { | 
					
						
							|  |  |  |         parent::__construct($message, $code, $previous); | 
					
						
							|  |  |  |         $this->availableIntervals = []; | 
					
						
							|  |  |  |         $this->periodicity        = Periodicity::Monthly; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-07-03 00:08:14 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-04 06:23:59 -03:00
										 |  |  |     public static function unavailable( | 
					
						
							|  |  |  |         Periodicity $periodicity, | 
					
						
							|  |  |  |         array       $intervals, | 
					
						
							|  |  |  |         int         $code = 0, | 
					
						
							| 
									
										
										
										
											2024-02-22 20:11:09 +01:00
										 |  |  |         ?\Throwable $previous = null | 
					
						
							| 
									
										
										
										
											2023-12-20 19:35:52 +01:00
										 |  |  |     ): self { | 
					
						
							| 
									
										
										
										
											2024-01-01 14:43:56 +01:00
										 |  |  |         $message                       = sprintf( | 
					
						
							| 
									
										
										
										
											2023-07-03 00:08:14 -03:00
										 |  |  |             'The periodicity %s is unknown. Choose one of available periodicity: %s', | 
					
						
							|  |  |  |             $periodicity->name, | 
					
						
							| 
									
										
										
										
											2023-11-04 14:18:49 +01:00
										 |  |  |             implode(', ', $intervals) | 
					
						
							| 
									
										
										
										
											2023-07-03 00:08:14 -03:00
										 |  |  |         ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-04 14:18:49 +01:00
										 |  |  |         $exception                     = new self($message, $code, $previous); | 
					
						
							| 
									
										
										
										
											2023-07-03 00:08:14 -03:00
										 |  |  |         $exception->periodicity        = $periodicity; | 
					
						
							| 
									
										
										
										
											2023-07-04 06:23:59 -03:00
										 |  |  |         $exception->availableIntervals = $intervals; | 
					
						
							| 
									
										
										
										
											2023-12-20 19:35:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-03 00:08:14 -03:00
										 |  |  |         return $exception; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |