Skip to content

Commit db632c6

Browse files
authored
Merge pull request #18 from rubyqorn/1.0.0
Constructor property promotion
2 parents 6057511 + 61200e1 commit db632c6

14 files changed

+65
-129
lines changed

src/AbstractSocket.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,16 @@
44

55
abstract class AbstractSocket
66
{
7-
/**
8-
* @var \Qonsillium\SocketFacade|null
9-
*/
10-
protected ?SocketFacade $facade = null;
11-
127
/**
138
* Initiate AbstractSocket constructor method
149
* and set SocketFacade property
1510
* @param \Qonsillium\SocketFacade $facade
1611
* @return void
17-
*/
18-
public function __construct(SocketFacade $facade)
19-
{
20-
$this->facade = $facade;
12+
*/
13+
public function __construct(
14+
protected SocketFacade $facade
15+
){
16+
//
2117
}
2218

2319
/**

src/ActionFactory.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,16 @@
1313

1414
class ActionFactory
1515
{
16-
/**
17-
* @var \Qonsillium\Credential\SocketCredentials|null;
18-
*/
19-
private ?SocketCredentials $credentials = null;
20-
2116
/**
2217
* Initiate ActionFactory constructor method and
2318
* set SocketCredetials property
2419
* @param \Qonsillium\Credential\SocketCredentials $credentials
2520
* @return void
26-
*/
27-
public function __construct(SocketCredentials $credentials)
28-
{
29-
$this->credentials = $credentials;
21+
*/
22+
public function __construct(
23+
private SocketCredentials $credentials
24+
){
25+
//
3026
}
3127

3228
/**

src/Actions/SocketConnector.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,27 @@
66

77
class SocketConnector extends AbstractSocketAction
88
{
9-
/**
10-
* @var string
11-
*/
12-
private string $address;
9+
// /**
10+
// * @var string
11+
// */
12+
// private string $address;
1313

14-
/**
15-
* @var string
16-
*/
17-
private string $type;
14+
// /**
15+
// * @var string
16+
// */
17+
// private string $type;
1818

1919
/**
2020
* Initiate SocketConnector constructor method
2121
* @param string $method
2222
* @param string $type
23-
* @return void
23+
* @return void
2424
*/
25-
public function __construct(string $address, string $type)
26-
{
27-
$this->address = $address;
28-
$this->type = $type;
25+
public function __construct(
26+
private string $address,
27+
private string $type
28+
){
29+
//
2930
}
3031

3132
/**

src/Actions/SocketReader.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,15 @@ class SocketReader extends AbstractSocketAction
99
*/
1010
private string $message;
1111

12-
/**
13-
* @var int
14-
*/
15-
private int $length;
16-
1712
/**
1813
* Initiate SocketReader constructor method
1914
* @param int $length
2015
* @return void
2116
*/
22-
public function __construct(int $length)
23-
{
24-
$this->length = $length;
17+
public function __construct(
18+
private int $length
19+
){
20+
//
2521
}
2622

2723
/**

src/Bootstrapper.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,6 @@
1010

1111
class Bootstrapper
1212
{
13-
/**
14-
* Configuration file with
15-
* yaml(yml) or json extension
16-
* @var string
17-
*/
18-
protected string $configFile;
19-
2013
/**
2114
* List with domain, type, protocol,
2215
* host and port socket settings
@@ -42,9 +35,9 @@ class Bootstrapper
4235
* @param string $configFile
4336
* @return void
4437
*/
45-
public function __construct(string $configFile)
46-
{
47-
$this->configFile = $configFile;
38+
public function __construct(
39+
protected string $configFile
40+
){
4841
$this->services = new ServiceProvider();
4942
$this->settings = $this->parseConfigFile();
5043
$this->configuration = $this->configureSettingsFromFile();

src/Parsers/ConfigParser.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,17 @@
44

55
abstract class ConfigParser
66
{
7-
/**
8-
* Configuration file
9-
* with settings
10-
* @var string
11-
*/
12-
protected string $file;
13-
147
/**
158
* Initiate ConfigParser constructor method.
169
* Configuration file can be only with json
1710
* or yaml(yml) extensions
1811
* @param string $file
19-
* @return void
12+
* @return void
2013
*/
21-
public function __construct(string $file)
22-
{
23-
$this->file = $file;
14+
public function __construct(
15+
protected string $file
16+
){
17+
//
2418
}
2519

2620
/**

src/Parsers/ConfigParsersFactory.php

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,6 @@
44

55
class ConfigParsersFactory
66
{
7-
/**
8-
* Configuration file which
9-
* will be parsed
10-
* @var string
11-
*/
12-
protected string $configFile;
13-
147
/**
158
* File extension
169
* @var string
@@ -20,20 +13,13 @@ class ConfigParsersFactory
2013
/**
2114
* Null object which make stub action.
2215
* Read: https://en.wikipedia.org/wiki/Null_object_pattern
23-
* @var \Qonsillium\Parsers\NullConfigFile
16+
* @var \Qonsillium\Parsers\ConfigParser
2417
*/
25-
protected $nullObj;
18+
protected ConfigParser $nullObj;
2619

27-
/**
28-
* Initiate ConfigParsersFactory constructor
29-
* method and set config file, extension and
30-
* null object
31-
* @param string $configFile
32-
* @return void
33-
*/
34-
public function __construct(string $configFile)
35-
{
36-
$this->configFile = $configFile;
20+
public function __construct(
21+
protected string $configFile,
22+
){
3723
$this->configFileExtension = pathinfo($this->configFile)['extension'];
3824
$this->nullObj = new NullConfigFile($this->configFile);
3925
}

src/Parsers/JSONConfigParser.php

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,7 @@ class JSONConfigParser extends ConfigParser
66
{
77
/**
88
* Parse json file with settings and return
9-
* it in assoc array interpretation.
10-
*
11-
* JSON config file example:
12-
* {
13-
* "settings": {
14-
* "domain": "AF_INET",
15-
* "type": "SOCK_STREAM",
16-
* "protocol": "SOL_TCP",
17-
* "host": "127.0.0.1",
18-
* "port": "8000",
19-
* }
20-
* }
21-
*
9+
* it in assoc array interpretation
2210
* @return array
2311
*/
2412
public function parse(): array

src/Parsers/NullConfigFile.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
class NullConfigFile extends ConfigParser
66
{
7+
/**
8+
* Stub method
9+
* @return array
10+
*/
711
public function parse(): array
812
{
913
return [];

src/Parsers/YAMLConfigParser.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,6 @@ class YAMLConfigParser extends ConfigParser
77
/**
88
* Parse yaml(yml) file with settings and return
99
* it in assoc array interpretation.
10-
*
11-
* YAML config file example:
12-
* settings:
13-
* domain: "AF_INET"
14-
* type: "SOCK_STREAM"
15-
* protocol: "SOL_TCP"
16-
* host: "127.0.0.1"
17-
* port: "8000"
18-
*
1910
* @return array
2011
*/
2112
public function parse(): array

0 commit comments

Comments
 (0)