Completed
Push — feat_email_envelope ( e5445d )
by Stefano
02:37
created

Email::using()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 7
rs 9.4285
cc 2
eloc 6
nc 2
nop 2
1
<?php
2
3
/**
4
 * Email
5
 *
6
 * Send messages via Email services.
7
 *
8
 * @package core
9
 * @author [email protected]
10
 * @copyright Caffeina srl - 2015 - http://caffeina.it
11
 */
12
13
14
class Email {
15
  use Module;
16
17
  protected static $driver,
18
                   $options,
19
                   $driver_name;
20
21
  protected static function instance(){
22
    return static::$driver;
23
  }
24
25
  public static function using($driver, $options = null){
26
    $class = '\\Email\\'.ucfirst(strtolower($driver));
27
    if ( ! class_exists($class) ) throw new \Exception("[Core.Email] : $driver driver not found.");
28
    static::$driver_name = $driver;
29
    static::$options = $options;
30
    static::$driver = new $class($options);
31
  }
32
33
  public static function clear(){
34
    static::using( static::$driver_name, static::$options );
35
  }
36
37
38
  public static function send(array $options){
39
    $mail = static::instance();
40
41
    $options = array_merge([
0 ignored issues
show
Unused Code introduced by
$options is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
42
      'to'          => false,
43
      'from'        => false,
44
      'replyTo'     => false,
45
      'subject'     => false,
46
      'message'     => false,
47
      'attachments' => [],
48
    ],$options);
49
50
    return $mail->send(new Envelope($option));
0 ignored issues
show
Bug introduced by
The variable $option does not exist. Did you mean $options?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
51
  }
52
53
}
54
55
Email::using('native');
56