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 | namespace Email; |
||
| 3 | |||
| 4 | require(dirname(__FILE__).'/../vendor/autoload.php'); |
||
| 5 | class AmazonSES extends EmailService |
||
| 6 | { |
||
| 7 | protected $ses; |
||
| 8 | |||
| 9 | public function __construct($params) |
||
| 10 | { |
||
| 11 | $provider = \Aws\Credentials\CredentialProvider::ini('default', $params['ini']); |
||
| 12 | //$credentials = \Aws\Common\Credentials\Credentials::fromIni('default', $params['ini']); |
||
|
0 ignored issues
–
show
|
|||
| 13 | |||
| 14 | $this->ses = \Aws\Ses\SesClient::factory([ |
||
|
0 ignored issues
–
show
|
|||
| 15 | 'version' => 'latest', |
||
| 16 | 'region' => 'us-west-2', |
||
| 17 | 'credentials' => $provider]); |
||
| 18 | } |
||
| 19 | |||
| 20 | public function canSend() |
||
| 21 | { |
||
| 22 | $result = $this->ses->getSendQuota(); |
||
| 23 | $result = $result->getAll(); |
||
|
0 ignored issues
–
show
The method
getAll() does not seem to exist on object<Aws\Result>.
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...
|
|||
| 24 | $res = $result['Max24HourSend'] - $result['SentLast24Hours']; |
||
| 25 | return $res; |
||
| 26 | } |
||
| 27 | |||
| 28 | public function sendEmail($email) |
||
| 29 | { |
||
| 30 | foreach($email->getToAddresses() as $to) |
||
| 31 | { |
||
| 32 | if(strstr($to, 'free.fr') !== false) |
||
| 33 | { |
||
| 34 | die('Spammer abuse filter!'); |
||
| 35 | } |
||
| 36 | } |
||
| 37 | |||
| 38 | if($email->hasAttachments()) |
||
| 39 | { |
||
| 40 | //Amazeon sendEmail doesn't support attachments. We need to use sendRawEmail |
||
| 41 | $args = array(); |
||
| 42 | $args['RawMessage'] = array(); |
||
| 43 | $args['RawMessage']['Data'] = base64_encode($email->getRawMessage()); |
||
| 44 | try { |
||
| 45 | return $this->ses->sendRawEmail($args); |
||
|
0 ignored issues
–
show
The return type of
return $this->ses->sendRawEmail($args); (Aws\Result) is incompatible with the return type of the parent method Email\EmailService::sendEmail of type boolean.
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design. Let’s take a look at an example: class Author {
private $name;
public function __construct($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
}
abstract class Post {
public function getAuthor() {
return 'Johannes';
}
}
class BlogPost extends Post {
public function getAuthor() {
return new Author('Johannes');
}
}
class ForumPost extends Post { /* ... */ }
function my_function(Post $post) {
echo strtoupper($post->getAuthor());
}
Our function Loading history...
|
|||
| 46 | } catch(\Exception $e) { |
||
| 47 | return false; |
||
| 48 | } |
||
| 49 | } |
||
| 50 | else |
||
| 51 | { |
||
| 52 | $args = array(); |
||
| 53 | $args['Source'] = $email->getFromAddress(); |
||
| 54 | $args['Destination'] = array(); |
||
| 55 | $args['Destination']['ToAddresses'] = $email->getToAddresses(); |
||
| 56 | $args['Destination']['CcAddresses'] = $email->getCCAddresses(); |
||
| 57 | $args['Destination']['BccAddresses'] = $email->getBCCAddresses(); |
||
| 58 | $args['Message'] = array(); |
||
| 59 | $args['Message']['Subject'] = array(); |
||
| 60 | $args['Message']['Subject']['Data'] = $email->getSubject(); |
||
| 61 | $args['Message']['Body'] = array(); |
||
| 62 | $args['Message']['Body']['Text'] = array(); |
||
| 63 | $args['Message']['Body']['Html'] = array(); |
||
| 64 | $args['Message']['Body']['Text']['Data'] = $email->getTextBody(); |
||
| 65 | $args['Message']['Body']['Html']['Data'] = $email->getHtmlBody(); |
||
| 66 | $args['ReplyToAddresses'] = array($email->getReplyTo()); |
||
| 67 | try { |
||
| 68 | return $this->ses->sendEmail($args); |
||
|
0 ignored issues
–
show
The return type of
return $this->ses->sendEmail($args); (Aws\Result) is incompatible with the return type of the parent method Email\EmailService::sendEmail of type boolean.
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design. Let’s take a look at an example: class Author {
private $name;
public function __construct($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
}
abstract class Post {
public function getAuthor() {
return 'Johannes';
}
}
class BlogPost extends Post {
public function getAuthor() {
return new Author('Johannes');
}
}
class ForumPost extends Post { /* ... */ }
function my_function(Post $post) {
echo strtoupper($post->getAuthor());
}
Our function Loading history...
|
|||
| 69 | } catch(\Exception $e) { |
||
| 70 | return false; |
||
| 71 | } |
||
| 72 | } |
||
| 73 | } |
||
| 74 | } |
||
| 75 | /* vim: set tabstop=4 shiftwidth=4 expandtab: */ |
||
| 76 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.