Skip to content

Commit 5040a6f

Browse files
committed
refactor: refactor php code for better readability with VSCode
1 parent c0ec66e commit 5040a6f

File tree

12 files changed

+150
-275
lines changed

12 files changed

+150
-275
lines changed

src/DataTypes/BTC.php

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,30 +48,24 @@ class BTC implements DataTypeInterface
4848

4949
/**
5050
* Generates the DataType Object and sets all of its properties.
51-
*
52-
* @param $arguments
5351
*/
54-
public function create(array $arguments)
52+
public function create(array $arguments): void
5553
{
5654
$this->setProperties($arguments);
5755
}
5856

5957
/**
6058
* Returns the correct QrCode format.
61-
*
62-
* @return string
6359
*/
64-
public function __toString()
60+
public function __toString(): string
6561
{
6662
return $this->buildBitCoinString();
6763
}
6864

6965
/**
7066
* Sets the BitCoin arguments.
71-
*
72-
* @param array $arguments
7367
*/
74-
protected function setProperties(array $arguments)
68+
protected function setProperties(array $arguments): self
7569
{
7670
if (isset($arguments[0])) {
7771
$this->address = $arguments[0];
@@ -84,14 +78,14 @@ protected function setProperties(array $arguments)
8478
if (isset($arguments[2])) {
8579
$this->setOptions($arguments[2]);
8680
}
81+
82+
return $this;
8783
}
8884

8985
/**
9086
* Sets the optional BitCoin options.
91-
*
92-
* @param array $options
9387
*/
94-
protected function setOptions(array $options)
88+
protected function setOptions(array $options): self
9589
{
9690
if (isset($options['label'])) {
9791
$this->label = $options['label'];
@@ -104,23 +98,23 @@ protected function setOptions(array $options)
10498
if (isset($options['returnAddress'])) {
10599
$this->returnAddress = $options['returnAddress'];
106100
}
101+
102+
return $this;
107103
}
108104

109105
/**
110106
* Builds a BitCoin string.
111-
*
112-
* @return string
113107
*/
114-
protected function buildBitCoinString()
108+
protected function buildBitCoinString(): string
115109
{
116-
$query = http_build_query([
110+
$query = \http_build_query([
117111
'amount' => $this->amount,
118112
'label' => $this->label,
119113
'message' => $this->message,
120114
'r' => $this->returnAddress,
121115
]);
122116

123-
$btc = $this->prefix.$this->address.'?'.$query;
117+
$btc = $this->prefix . $this->address . '?' . $query;
124118

125119
return $btc;
126120
}

src/DataTypes/DataTypeInterface.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@ interface DataTypeInterface
77
/**
88
* Generates the DataType Object and sets all of its properties.
99
*/
10-
public function create(array $arguments);
10+
public function create(array $arguments): void;
1111

1212
/**
1313
* Returns the correct QrCode format.
14-
*
15-
* @return string
1614
*/
17-
public function __toString();
15+
public function __toString(): string;
1816
}

src/DataTypes/Email.php

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,50 +36,42 @@ class Email implements DataTypeInterface
3636

3737
/**
3838
* Generates the DataType Object and sets all of its properties.
39-
*
40-
* @param $arguments
4139
*/
42-
public function create(array $arguments)
40+
public function create(array $arguments): void
4341
{
4442
$this->setProperties($arguments);
4543
}
4644

4745
/**
4846
* Returns the correct QrCode format.
49-
*
50-
* @return string
5147
*/
52-
public function __toString()
48+
public function __toString(): string
5349
{
5450
return $this->buildEmailString();
5551
}
5652

5753
/*
5854
* Builds the email string.
59-
*
60-
* @return string
6155
*/
62-
protected function buildEmailString()
56+
protected function buildEmailString(): string
6357
{
64-
$email = $this->prefix.$this->email;
58+
$email = $this->prefix . $this->email;
6559

6660
if (isset($this->subject) || isset($this->body)) {
6761
$data = [
6862
'subject' => $this->subject,
6963
'body' => $this->body,
7064
];
71-
$email .= '?'.http_build_query($data);
65+
$email .= '?' . \http_build_query($data);
7266
}
7367

7468
return $email;
7569
}
7670

7771
/**
7872
* Sets the objects properties.
79-
*
80-
* @param $arguments
8173
*/
82-
protected function setProperties(array $arguments)
74+
protected function setProperties(array $arguments): self
8375
{
8476
if (isset($arguments[0])) {
8577
$this->setEmail($arguments[0]);
@@ -90,28 +82,30 @@ protected function setProperties(array $arguments)
9082
if (isset($arguments[2])) {
9183
$this->body = $arguments[2];
9284
}
85+
86+
return $this;
9387
}
9488

9589
/**
9690
* Sets the email property.
97-
*
98-
* @param $email
91+
*
92+
* @throws \BaconQrCode\Exception\InvalidArgumentException
9993
*/
100-
protected function setEmail($email)
94+
protected function setEmail(string $email): self
10195
{
10296
if ($this->isValidEmail($email)) {
10397
$this->email = $email;
10498
}
99+
100+
return $this;
105101
}
106102

107103
/**
108104
* Ensures an email is valid.
109105
*
110-
* @param string $email
111-
*
112-
* @return bool
106+
* @throws \BaconQrCode\Exception\InvalidArgumentException
113107
*/
114-
protected function isValidEmail($email)
108+
protected function isValidEmail(string $email): bool
115109
{
116110
if (! filter_var($email, FILTER_VALIDATE_EMAIL)) {
117111
throw new InvalidArgumentException('Invalid email provided');

src/DataTypes/Geo.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,35 +21,34 @@ class Geo implements DataTypeInterface
2121
/**
2222
* The latitude.
2323
*
24-
* @var
24+
* @var double
2525
*/
2626
protected $latitude;
2727

2828
/**
2929
* The longitude.
3030
*
31-
* @var
31+
* @var double
3232
*/
3333
protected $longitude;
3434

3535
/**
3636
* Generates the DataType Object and sets all of its properties.
37-
*
38-
* @param $arguments
3937
*/
40-
public function create(array $arguments)
38+
public function create(array $arguments): void
4139
{
4240
$this->latitude = $arguments[0];
4341
$this->longitude = $arguments[1];
4442
}
4543

4644
/**
4745
* Returns the correct QrCode format.
48-
*
49-
* @return string
5046
*/
51-
public function __toString()
47+
public function __toString(): string
5248
{
53-
return $this->prefix.$this->latitude.$this->separator.$this->longitude;
49+
return $this->prefix
50+
. \strval($this->latitude)
51+
. $this->separator
52+
. \strval($this->longitude);
5453
}
5554
}

src/DataTypes/PhoneNumber.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,23 @@ class PhoneNumber implements DataTypeInterface
1414
/**
1515
* The phone number.
1616
*
17-
* @var
17+
* @var string
1818
*/
1919
protected $phoneNumber;
2020

2121
/**
2222
* Generates the DataType Object and sets all of its properties.
23-
*
24-
* @param $arguments
2523
*/
26-
public function create(array $arguments)
24+
public function create(array $arguments): void
2725
{
2826
$this->phoneNumber = $arguments[0];
2927
}
3028

3129
/**
3230
* Returns the correct QrCode format.
33-
*
34-
* @return string
3531
*/
36-
public function __toString()
32+
public function __toString(): string
3733
{
38-
return $this->prefix.$this->phoneNumber;
34+
return $this->prefix . $this->phoneNumber;
3935
}
4036
}

src/DataTypes/SMS.php

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,50 +34,44 @@ class SMS implements DataTypeInterface
3434

3535
/**
3636
* Generates the DataType Object and sets all of its properties.
37-
*
38-
* @param $arguments
3937
*/
40-
public function create(array $arguments)
38+
public function create(array $arguments): void
4139
{
4240
$this->setProperties($arguments);
4341
}
4442

4543
/**
4644
* Returns the correct QrCode format.
47-
*
48-
* @return string
4945
*/
50-
public function __toString()
46+
public function __toString(): string
5147
{
5248
return $this->buildSMSString();
5349
}
5450

5551
/**
5652
* Sets the phone number and message for a sms message.
57-
*
58-
* @param array $arguments
5953
*/
60-
protected function setProperties(array $arguments)
54+
protected function setProperties(array $arguments): self
6155
{
6256
if (isset($arguments[0])) {
6357
$this->phoneNumber = $arguments[0];
6458
}
6559
if (isset($arguments[1])) {
6660
$this->message = $arguments[1];
6761
}
62+
63+
return $this;
6864
}
6965

7066
/**
7167
* Builds a SMS string.
72-
*
73-
* @return string
7468
*/
75-
protected function buildSMSString()
69+
protected function buildSMSString(): string
7670
{
77-
$sms = $this->prefix.$this->phoneNumber;
71+
$sms = $this->prefix . $this->phoneNumber;
7872

7973
if (isset($this->message)) {
80-
$sms .= $this->separator.$this->message;
74+
$sms .= $this->separator . $this->message;
8175
}
8276

8377
return $sms;

src/DataTypes/WiFi.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,30 +48,24 @@ class WiFi implements DataTypeInterface
4848

4949
/**
5050
* Generates the DataType Object and sets all of its properties.
51-
*
52-
* @param $arguments
5351
*/
54-
public function create(array $arguments)
52+
public function create(array $arguments): void
5553
{
5654
$this->setProperties($arguments);
5755
}
5856

5957
/**
6058
* Returns the correct QrCode format.
61-
*
62-
* @return string
6359
*/
64-
public function __toString()
60+
public function __toString(): string
6561
{
6662
return $this->buildWifiString();
6763
}
6864

6965
/**
7066
* Builds the WiFi string.
71-
*
72-
* @return string
7367
*/
74-
protected function buildWifiString()
68+
protected function buildWifiString(): string
7569
{
7670
$wifi = $this->prefix;
7771

@@ -93,10 +87,8 @@ protected function buildWifiString()
9387

9488
/**
9589
* Sets the WiFi properties.
96-
*
97-
* @param $arguments
9890
*/
99-
protected function setProperties(array $arguments)
91+
protected function setProperties(array $arguments): self
10092
{
10193
$arguments = $arguments[0];
10294
if (isset($arguments['encryption'])) {
@@ -111,5 +103,7 @@ protected function setProperties(array $arguments)
111103
if (isset($arguments['hidden'])) {
112104
$this->hidden = $arguments['hidden'];
113105
}
106+
107+
return $this;
114108
}
115109
}

0 commit comments

Comments
 (0)