ClientBuilder::build()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 16
rs 9.4285
cc 3
eloc 10
nc 4
nop 0
1
<?php
2
3
namespace FastAPNS;
4
5
class ClientBuilder {
6
  private $stream_socket_client;
7
  private $local_cert;
8
  private $passphrase;
9
  private $host;
10
  private $port;
11
  private $batch_size;
12
13
  const FASTAPNS_BATCH_SIZE_DEFAULT = 1700;
14
15
  public static function create() {
16
    return new static();
17
  }
18
19
  public function __construct() {
20
    $this->host = ClientStreamSocket::FASTAPNS_DEFAULT_GATEWAY_HOST;
21
    $this->port = ClientStreamSocket::FASTAPNS_DEFAULT_GATEWAY_PORT;
22
  }
23
24
  public function setStreamSocketClient($stream_socket_client) {
25
    $this->stream_socket_client = $stream_socket_client;
26
27
    return $this;
28
  }
29
30
  public function setLocalCert($local_cert) {
31
    $this->local_cert = $local_cert;
32
33
    return $this;
34
  }
35
36
  public function setPassphrase($passphrase) {
37
    $this->passphrase = $passphrase;
38
39
    return $this;
40
  }
41
42
  public function setHost($host) {
43
    $this->host = $host;
44
45
    return $this;
46
  }
47
48
  public function setPort($port) {
49
    $this->port = $port;
50
51
    return $this;
52
  }
53
54
  public function setBatchSize($batch_size) {
55
    $this->batch_size = $batch_size;
56
57
    return $this;
58
  }
59
60
  public function build() {
61
    if (!$this->stream_socket_client) {
62
      $this->stream_socket_client = new ClientStreamSocket(
63
        $this->local_cert,
64
        $this->passphrase,
65
        $this->host,
66
        $this->port
67
      );
68
    }
69
70
    if (!$this->batch_size) {
71
      $this->batch_size = Client::FASTAPNS_BATCH_SIZE_DEFAULT;
72
    }
73
74
    return new Client($this->stream_socket_client, $this->batch_size);
75
  }
76
}
77