Your project must not contain invalid function or method calls 11
- Read doc
- Reliability
- Major
More information: https://insight.symfony.com/what-we-analyse/php.invalid_call
- {
- $isValidInstance = $this instanceof Mailable || $this instanceof MailMessage;
- if ($isValidInstance && $this->mailDriver() == 'sendgrid') {
- $this->withSymfonyMessage(function (Email $email) use ($params) {
- $email->embed(static::sgEncode($params), SendgridTransport::REQUEST_BODY_PARAMETER);
- });
- }
- return $this;
- }
- public function register()
- {
- $this->app->afterResolving(MailManager::class, function (MailManager $mail_manager) {
- $mail_manager->extend('sendgrid', function ($config) {
- if (! isset($config['api_key'])) {
- $config = $this->app['config']->get('services.sendgrid', []);
- }
- $client = new HttpClient(Arr::get($config, 'guzzle', []));
- $endpoint = $config['endpoint'] ?? null;
- return new SendgridTransport($client, $config['api_key'], $endpoint);
- $this->app->afterResolving(MailManager::class, function (MailManager $mail_manager) {
- $mail_manager->extend('sendgrid', function ($config) {
- if (! isset($config['api_key'])) {
- $config = $this->app['config']->get('services.sendgrid', []);
- }
- $client = new HttpClient(Arr::get($config, 'guzzle', []));
- $endpoint = $config['endpoint'] ?? null;
- return new SendgridTransport($client, $config['api_key'], $endpoint);
- });
- parent::__construct();
- }
- protected function doSend(SentMessage $message): void
- {
- $email = MessageConverter::toEmail($message->getOriginalMessage());
- $data = [
- 'personalizations' => $this->getPersonalizations($email),
- 'from' => $this->getFrom($email),
- 'subject' => $email->getSubject(),
- $messageId = $response->getHeaderLine('X-Message-Id');
- $message->setMessageId($messageId);
- $message->getOriginalMessage()
- ->getHeaders()
- ->addTextHeader('X-Sendgrid-Message-Id', $messageId);
- }
- /**
- $messageId = $response->getHeaderLine('X-Message-Id');
- $message->setMessageId($messageId);
- $message->getOriginalMessage()
- ->getHeaders()
- ->addTextHeader('X-Sendgrid-Message-Id', $messageId);
- }
- /**
- case 'api_key':
- $this->apiKey = $val;
- continue 2;
- case 'personalizations':
- $this->setPersonalizations($data, $val);
- continue 2;
- case 'attachments':
- $val = array_merge($this->attachments, $val);
- break;
- case 'personalizations':
- $this->setPersonalizations($data, $val);
- continue 2;
- case 'attachments':
- $val = array_merge($this->attachments, $val);
- break;
- }
- Arr::set($data, $key, $val);
- }
- case 'personalizations':
- $this->setPersonalizations($data, $val);
- continue 2;
- case 'attachments':
- $val = array_merge($this->attachments, $val);
- break;
- }
- Arr::set($data, $key, $val);
- }
- *
- * @throws ClientException
- */
- protected function post($payload)
- {
- return $this->client->request('POST', $this->endpoint, $payload);
- }
- public function __toString(): string
- {
- return 'sendgrid';
- *
- * @throws ClientException
- */
- protected function post($payload)
- {
- return $this->client->request('POST', $this->endpoint, $payload);
- }
- public function __toString(): string
- {
- return 'sendgrid';
Your project should not use invalid return types 3
- Read doc
- Reliability
- Major
More information: https://insight.symfony.com/what-we-analyse/php.invalid_return_typehint
- /**
- * @return string
- */
- private function mailDriver()
- {
- return function_exists('config') ? config('mail.default', config('mail.driver')) : env('MAIL_MAILER', env('MAIL_DRIVER'));
- }
- /**
- * @param array $params
- * @return string
- {
- if (is_string($params)) {
- return $params;
- }
- return json_encode($params);
- }
- /**
- * @param string $strParams
- * @return array
- return $attachments;
- }
- private function getAttachmentName(DataPart $dataPart): string
- {
- return $dataPart->getPreparedHeaders()->getHeaderParameter('Content-Disposition', 'filename');
- }
- private function getAttachmentContentType(DataPart $dataPart): string
- {
- return $dataPart->getMediaType().'/'.$dataPart->getMediaSubtype();
Your project should not use invalid parameter and return typehints 6
- Read doc
- Reliability
- Major
More information: https://insight.symfony.com/what-we-analyse/php.invalid_typehint
- {
- /**
- * @param null|array $params
- * @return $this
- */
- public function sendgrid($params)
- {
- $isValidInstance = $this instanceof Mailable || $this instanceof MailMessage;
- if ($isValidInstance && $this->mailDriver() == 'sendgrid') {
- $this->withSymfonyMessage(function (Email $email) use ($params) {
- /**
- * @param array $params
- * @return string
- */
- public static function sgEncode($params)
- {
- if (is_string($params)) {
- return $params;
- }
- private function getAttachmentContentType(DataPart $dataPart): string
- {
- return $dataPart->getMediaType().'/'.$dataPart->getMediaSubtype();
- }
- private function setParameters(Email $email, array $data): array
- {
- $smtp_api = [];
- foreach ($email->getAttachments() as $attachment) {
- $name = $attachment->getPreparedHeaders()->getHeaderParameter('Content-Disposition', 'filename');
- if ($name === self::REQUEST_BODY_PARAMETER) {
- }
- return $data;
- }
- private function setPersonalizations(array &$data, array $personalizations): void
- {
- foreach ($personalizations as $index => $params) {
- foreach ($params as $key => $val) {
- if (in_array($key, ['to', 'cc', 'bcc'])) {
- Arr::set($data, 'personalizations.'.$index.'.'.$key, $val);
- }
- return $data;
- }
- private function setPersonalizations(array &$data, array $personalizations): void
- {
- foreach ($personalizations as $index => $params) {
- foreach ($params as $key => $val) {
- if (in_array($key, ['to', 'cc', 'bcc'])) {
- Arr::set($data, 'personalizations.'.$index.'.'.$key, $val);
- * @param array $payload
- * @return ResponseInterface
- *
- * @throws ClientException
- */
- protected function post($payload)
- {
- return $this->client->request('POST', $this->endpoint, $payload);
- }
- public function __toString(): string
Your project should use return types 8
- Read doc
- Reliability
- Major
More information: https://insight.symfony.com/what-we-analyse/php.missing_return_typehint
- /**
- * @param string $strParams
- * @return array
- */
- public static function sgDecode($strParams)
- {
- if (! is_string($strParams)) {
- return (array) $strParams;
- }
- $params = json_decode($strParams, true);
- }
- /**
- * @return array[]
- */
- private function getPersonalizations(Email $email): array
- {
- $personalization['to'] = $this->setAddress($email->getTo());
- if (count($email->getCc()) > 0) {
- $personalization['cc'] = $this->setAddress($email->getCc());
- }
- /**
- * @param Address[] $addresses
- */
- private function setAddress(array $addresses): array
- {
- $recipients = [];
- foreach ($addresses as $address) {
- $recipient = ['email' => $address->getAddress()];
- if ($address->getName() !== '') {
- }
- return $recipients;
- }
- private function getFrom(Email $email): array
- {
- if (count($email->getFrom()) > 0) {
- foreach ($email->getFrom() as $from) {
- return ['email' => $from->getAddress(), 'name' => $from->getName()];
- }
- }
- return [];
- }
- private function getContents(Email $email): array
- {
- $contents = [];
- if (! is_null($email->getTextBody())) {
- $contents[] = [
- 'type' => 'text/plain',
- }
- return $contents;
- }
- private function getReplyTo(Email $email): ?array
- {
- if (count($email->getReplyTo()) > 0) {
- $replyTo = $email->getReplyTo()[0];
- return [
- }
- return null;
- }
- private function getAttachments(Email $email): array
- {
- $attachments = [];
- foreach ($email->getAttachments() as $attachment) {
- $filename = $this->getAttachmentName($attachment);
- if ($filename === self::REQUEST_BODY_PARAMETER) {
- private function getAttachmentContentType(DataPart $dataPart): string
- {
- return $dataPart->getMediaType().'/'.$dataPart->getMediaSubtype();
- }
- private function setParameters(Email $email, array $data): array
- {
- $smtp_api = [];
- foreach ($email->getAttachments() as $attachment) {
- $name = $attachment->getPreparedHeaders()->getHeaderParameter('Content-Disposition', 'filename');
- if ($name === self::REQUEST_BODY_PARAMETER) {
Your project must not contain invalid instantiations 3
- Read doc
- Reliability
- Major
More information: https://insight.symfony.com/what-we-analyse/php.invalid_instantiation
- $this->app->afterResolving(MailManager::class, function (MailManager $mail_manager) {
- $mail_manager->extend('sendgrid', function ($config) {
- if (! isset($config['api_key'])) {
- $config = $this->app['config']->get('services.sendgrid', []);
- }
- $client = new HttpClient(Arr::get($config, 'guzzle', []));
- $endpoint = $config['endpoint'] ?? null;
- return new SendgridTransport($client, $config['api_key'], $endpoint);
- });
- $config = $this->app['config']->get('services.sendgrid', []);
- }
- $client = new HttpClient(Arr::get($config, 'guzzle', []));
- $endpoint = $config['endpoint'] ?? null;
- return new SendgridTransport($client, $config['api_key'], $endpoint);
- });
- });
- }
- }
- $config = $this->app['config']->get('services.sendgrid', []);
- }
- $client = new HttpClient(Arr::get($config, 'guzzle', []));
- $endpoint = $config['endpoint'] ?? null;
- return new SendgridTransport($client, $config['api_key'], $endpoint);
- });
- });
- }
- }
Your project should only use iterable types in foreach loops
- Read doc
- Reliability
- Major
More information: https://insight.symfony.com/what-we-analyse/php.invalid_foreach_iterable
- }
- private function setPersonalizations(array &$data, array $personalizations): void
- {
- foreach ($personalizations as $index => $params) {
- foreach ($params as $key => $val) {
- if (in_array($key, ['to', 'cc', 'bcc'])) {
- Arr::set($data, 'personalizations.'.$index.'.'.$key, $val);
- $this->numberOfRecipients++;
- } else {
- Arr::set($data, 'personalizations.'.$index.'.'.$key, $val);
Your project uses non-strict array lookups
- Read doc
- Reliability
- Major
More information: https://insight.symfony.com/what-we-analyse/php.strict_array_lookup
- private function setPersonalizations(array &$data, array $personalizations): void
- {
- foreach ($personalizations as $index => $params) {
- foreach ($params as $key => $val) {
- if (in_array($key, ['to', 'cc', 'bcc'])) {
- Arr::set($data, 'personalizations.'.$index.'.'.$key, $val);
- $this->numberOfRecipients++;
- } else {
- Arr::set($data, 'personalizations.'.$index.'.'.$key, $val);
- }