BurningFlipside /
CommonCode
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Email Router class |
||
| 4 | * |
||
| 5 | * This file describes the Email Router class |
||
| 6 | * |
||
| 7 | * PHP version 5 and 7 |
||
| 8 | * |
||
| 9 | * @author Patrick Boyd / [email protected] |
||
| 10 | * @copyright Copyright (c) 2016, Austin Artistic Reconstruction |
||
| 11 | * @license http://www.apache.org/licenses/ Apache 2.0 License |
||
| 12 | */ |
||
| 13 | |||
| 14 | namespace Email; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * An class to represent an Email Router |
||
| 18 | */ |
||
| 19 | class EmailRouter extends \Singleton |
||
| 20 | { |
||
| 21 | protected function __construct() |
||
| 22 | { |
||
| 23 | } |
||
| 24 | |||
| 25 | public function routeSingle($destination, $rawMessage) |
||
| 26 | { |
||
| 27 | $route = $this->getRouteFromDestination($destination); |
||
| 28 | if($route === false || $route === null) |
||
| 29 | { |
||
| 30 | return false; |
||
| 31 | } |
||
| 32 | return $route->route($destination, $rawMessage); |
||
| 33 | } |
||
| 34 | |||
| 35 | public function routeMany($destinations, $rawMessage) |
||
| 36 | { |
||
| 37 | $ret = array(); |
||
| 38 | $tmp = false; |
||
|
0 ignored issues
–
show
|
|||
| 39 | $error = false; |
||
| 40 | foreach($destinations as $dest) |
||
| 41 | { |
||
| 42 | $tmp = $this->routeSingle($dest, $rawMessage); |
||
| 43 | $ret[] = $tmp; |
||
| 44 | if($tmp === false) $error = true; |
||
| 45 | } |
||
| 46 | if($error === true) |
||
| 47 | { |
||
| 48 | return $ret; |
||
| 49 | } |
||
| 50 | return true; |
||
| 51 | } |
||
| 52 | |||
| 53 | public function getRouteFromDestination($destination) |
||
| 54 | { |
||
| 55 | $dataSet = \DataSetFactory::get_data_set('email'); |
||
|
0 ignored issues
–
show
The method
get_data_set() does not seem to exist on object<DataSetFactory>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 56 | $dataTable = $dataSet['Routes']; |
||
| 57 | if(!(preg_match('/(.*)@(.*)/', $destination, $parts))) |
||
| 58 | { |
||
| 59 | return false; |
||
| 60 | } |
||
| 61 | $routeData = $dataTable->read(array('pattern'=>array('$regex'=>new \MongoRegex('/'.$parts[1].'@/i')))); |
||
| 62 | if($routeData === false) |
||
| 63 | { |
||
| 64 | return false; |
||
| 65 | } |
||
| 66 | $count = count($routeData); |
||
| 67 | if($count === 0) |
||
| 68 | { |
||
| 69 | return false; |
||
| 70 | } |
||
| 71 | else if($count > 1) |
||
| 72 | { |
||
| 73 | //TODO Best Fit |
||
| 74 | throw new \Exception('Multiple Routes match! Not implemented!'); |
||
| 75 | } |
||
| 76 | $routeData = $routeData[0]; |
||
| 77 | $type = $routeData['type']; |
||
| 78 | if(isset($routeData['data'])) |
||
| 79 | { |
||
| 80 | return new $type($routeData['data']); |
||
| 81 | } |
||
| 82 | else |
||
| 83 | { |
||
| 84 | return new $type(); |
||
| 85 | } |
||
| 86 | return false; |
||
|
0 ignored issues
–
show
return false; does not seem to be reachable.
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed. Unreachable code is most often the result of function fx() {
try {
doSomething();
return true;
}
catch (\Exception $e) {
return false;
}
return false;
}
In the above example, the last Loading history...
|
|||
| 87 | } |
||
| 88 | } |
||
| 89 | /* vim: set tabstop=4 shiftwidth=4 expandtab: */ |
||
| 90 | ?> |
||
|
0 ignored issues
–
show
It is not recommended to use PHP's closing tag
?> in files other than templates.
Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore. A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever. Loading history...
|
|||
| 91 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.