These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * EmailProvider class |
||
4 | * |
||
5 | * This file describes the Singleton EmailProvider class |
||
6 | * |
||
7 | * PHP version 5 and 7 |
||
8 | * |
||
9 | * @author Patrick Boyd / [email protected] |
||
10 | * @copyright Copyright (c) 2015, Austin Artistic Reconstruction |
||
11 | * @license http://www.apache.org/licenses/ Apache 2.0 License |
||
12 | */ |
||
13 | |||
14 | /** |
||
15 | * use the FlipsideSettings class |
||
16 | */ |
||
17 | require_once("/var/www/secure_settings/class.FlipsideSettings.php"); |
||
18 | |||
19 | /** |
||
20 | * Allow other classes to be loaded as needed |
||
21 | */ |
||
22 | require_once('Autoload.php'); |
||
23 | |||
24 | /** |
||
25 | * A singleton class allowing the caller to send Email |
||
26 | * |
||
27 | * This class will abstract out how email is sent |
||
28 | */ |
||
29 | class EmailProvider extends Provider |
||
30 | { |
||
31 | /** An array of methods that can be used to send email */ |
||
32 | protected $methods; |
||
33 | |||
34 | /** |
||
35 | * Enumerate all supported EmailServices and instacetate them |
||
36 | */ |
||
37 | View Code Duplication | protected function __construct() |
|
0 ignored issues
–
show
|
|||
38 | { |
||
39 | $this->methods = array(); |
||
40 | if(isset(FlipsideSettings::$email_providers)) |
||
41 | { |
||
42 | $keys = array_keys(FlipsideSettings::$email_providers); |
||
43 | $count = count($keys); |
||
44 | for($i = 0; $i < $count; $i++) |
||
45 | { |
||
46 | $class = $keys[$i]; |
||
47 | array_push($this->methods, new $class(FlipsideSettings::$email_providers[$keys[$i]])); |
||
48 | } |
||
49 | } |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * Send the email |
||
54 | * |
||
55 | * @param Email\Email $email The email message to send |
||
56 | * @param string $methodName The class name of the email method |
||
57 | * |
||
58 | * @return boolean True if the email was sent, false otherwise |
||
59 | */ |
||
60 | public function sendEmail($email, $methodName = false) |
||
61 | { |
||
62 | if($methodName === false) |
||
63 | { |
||
64 | $res = false; |
||
65 | $count = count($this->methods); |
||
66 | for($i = 0; $i < $count; $i++) |
||
67 | { |
||
68 | $res = $this->methods[$i]->sendEmail($email); |
||
69 | if($res !== false) |
||
70 | { |
||
71 | return $res; |
||
72 | } |
||
73 | } |
||
74 | return $res; |
||
75 | } |
||
76 | else |
||
77 | { |
||
78 | $method = $this->getMethodByName($methodName); |
||
79 | return $method->sendEmail($email); |
||
80 | } |
||
81 | } |
||
82 | } |
||
83 | /* vim: set tabstop=4 shiftwidth=4 expandtab: */ |
||
84 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.