MailJobBuilder::make()   A
last analyzed

Complexity

Conditions 6
Paths 6

Size

Total Lines 18
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
eloc 15
c 1
b 0
f 0
nc 6
nop 2
dl 0
loc 18
rs 9.2222
1
<?php
2
3
namespace Da\Mailer\Builder;
4
5
use Da\Mailer\Enum\MessageBrokerEnum;
6
use Da\Mailer\Exception\UndefinedMessageBrokerException;
7
use Da\Mailer\Model\MailJob;
8
use Da\Mailer\Queue\Backend\Beanstalkd\BeanstalkdMailJob;
9
use Da\Mailer\Queue\Backend\Pdo\PdoMailJob;
10
use Da\Mailer\Queue\Backend\RabbitMq\RabbitMqJob;
11
use Da\Mailer\Queue\Backend\Redis\RedisMailJob;
12
use Da\Mailer\Queue\Backend\Sqs\SqsMailJob;
13
14
class MailJobBuilder extends Buildable
15
{
16
    /**
17
     * @param array|null $jobAttributes
18
     * @param string|null $broker
19
     * @return MailJob
20
     * @throws UndefinedMessageBrokerException
21
     */
22
    public static function make($jobAttributes = null, ?string $broker = null): MailJob
23
    {
24
        $config = self::getConfig();
25
        $messageBroker = $broker ?? $config['config']['message_broker'];
26
27
        switch ($messageBroker) {
28
            case MessageBrokerEnum::BROKER_REDIS:
29
                return new RedisMailJob($jobAttributes);
0 ignored issues
show
Bug introduced by
It seems like $jobAttributes can also be of type null; however, parameter $config of Da\Mailer\Queue\Backend\...sMailJob::__construct() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

29
                return new RedisMailJob(/** @scrutinizer ignore-type */ $jobAttributes);
Loading history...
Bug Best Practice introduced by
The expression return new Da\Mailer\Que...MailJob($jobAttributes) returns the type Da\Mailer\Queue\Backend\Redis\RedisMailJob which is incompatible with the return type mandated by Da\Mailer\Builder\Buildable::make() of void.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
30
            case MessageBrokerEnum::BROKER_SQS:
31
                return new SqsMailJob($jobAttributes);
0 ignored issues
show
Bug Best Practice introduced by
The expression return new Da\Mailer\Que...MailJob($jobAttributes) returns the type Da\Mailer\Queue\Backend\Sqs\SqsMailJob which is incompatible with the return type mandated by Da\Mailer\Builder\Buildable::make() of void.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
Bug introduced by
It seems like $jobAttributes can also be of type null; however, parameter $config of Da\Mailer\Queue\Backend\...sMailJob::__construct() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

31
                return new SqsMailJob(/** @scrutinizer ignore-type */ $jobAttributes);
Loading history...
32
            case MessageBrokerEnum::BROKER_BEANSTALKD:
33
                return new BeanstalkdMailJob($jobAttributes);
0 ignored issues
show
Bug Best Practice introduced by
The expression return new Da\Mailer\Que...MailJob($jobAttributes) returns the type Da\Mailer\Queue\Backend\...talkd\BeanstalkdMailJob which is incompatible with the return type mandated by Da\Mailer\Builder\Buildable::make() of void.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
Bug introduced by
It seems like $jobAttributes can also be of type null; however, parameter $config of Da\Mailer\Queue\Backend\...dMailJob::__construct() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

33
                return new BeanstalkdMailJob(/** @scrutinizer ignore-type */ $jobAttributes);
Loading history...
34
            case MessageBrokerEnum::BROKER_PDO:
35
                return new PdoMailJob($jobAttributes);
0 ignored issues
show
Bug Best Practice introduced by
The expression return new Da\Mailer\Que...MailJob($jobAttributes) returns the type Da\Mailer\Queue\Backend\Pdo\PdoMailJob which is incompatible with the return type mandated by Da\Mailer\Builder\Buildable::make() of void.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
Bug introduced by
It seems like $jobAttributes can also be of type null; however, parameter $config of Da\Mailer\Queue\Backend\...oMailJob::__construct() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

35
                return new PdoMailJob(/** @scrutinizer ignore-type */ $jobAttributes);
Loading history...
36
            case MessageBrokerEnum::BROKER_RABBITMQ:
37
                return new RabbitMqJob($jobAttributes);
0 ignored issues
show
Bug introduced by
It seems like $jobAttributes can also be of type null; however, parameter $config of Da\Mailer\Queue\Backend\...bitMqJob::__construct() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

37
                return new RabbitMqJob(/** @scrutinizer ignore-type */ $jobAttributes);
Loading history...
Bug Best Practice introduced by
The expression return new Da\Mailer\Que...itMqJob($jobAttributes) returns the type Da\Mailer\Queue\Backend\RabbitMq\RabbitMqJob which is incompatible with the return type mandated by Da\Mailer\Builder\Buildable::make() of void.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
38
            default:
39
                throw new UndefinedMessageBrokerException();
40
        }
41
    }
42
}
43