Skip to content

Commit f68d3a9

Browse files
committed
refactor to php 7+
1 parent 73fa895 commit f68d3a9

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

src/Presenter.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types = 1);
22

33
namespace Nahid\Presento;
44

@@ -9,23 +9,23 @@ abstract class Presenter
99
protected $data = [];
1010
protected $generatedData = [];
1111

12-
public function __construct($data)
12+
public function __construct(array $data)
1313
{
1414
$this->data = $data;
1515
$this->generatedData = $this->handle();
1616
}
1717

18-
public function __invoke()
18+
public function __invoke() : array
1919
{
2020
return $this->generatedData;
2121
}
2222

23-
public function __toString()
23+
public function __toString() : string
2424
{
2525
return json_encode($this->generatedData);
2626
}
2727

28-
abstract public function present();
28+
abstract public function present() : array;
2929

3030
public function transformer()
3131
{
@@ -46,7 +46,7 @@ public function handle()
4646
return $this->transform($this->process($this->data));
4747
}
4848

49-
public function process($data)
49+
public function process(array $data) : array
5050
{
5151
$present = $this->present();
5252
$record = [];
@@ -72,7 +72,7 @@ public function process($data)
7272
return $record;
7373
}
7474

75-
protected function transform($data)
75+
protected function transform(array $data) : array
7676
{
7777
$transformerClass = $this->transformer();
7878

@@ -84,12 +84,12 @@ protected function transform($data)
8484
return $data;
8585
}
8686

87-
public function toJson()
87+
public function toJson() : string
8888
{
8989
return json_encode($this->generatedData);
9090
}
9191

92-
public function get()
92+
public function get() : array
9393
{
9494
return $this->generatedData;
9595
}
@@ -100,7 +100,7 @@ public function get()
100100
* @param array $arr
101101
* @return bool
102102
*/
103-
protected function isCollection($arr)
103+
protected function isCollection(array $arr) : bool
104104
{
105105
if (!is_array($arr)) {
106106
return false;

src/Transformer.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types = 1);
22

33
namespace Nahid\Presento;
44

@@ -8,13 +8,13 @@ abstract class Transformer
88
protected $generatedData = [];
99
private $data = [];
1010

11-
public function __construct($data)
11+
public function __construct(array $data)
1212
{
1313
$this->data = $data;
1414
$this->transform();
1515
}
1616

17-
public function __invoke()
17+
public function __invoke() : array
1818
{
1919
return $this->getData();
2020
}
@@ -26,19 +26,19 @@ public function transform()
2626
}
2727
}
2828

29-
protected function isPropertyNeedProcess($property)
29+
protected function isPropertyNeedProcess(string $property) : bool
3030
{
3131
$method = $this->getPropertyFunction($property);
3232

3333
return method_exists($this, $method);
3434
}
3535

36-
protected function getPropertyFunction($property)
36+
protected function getPropertyFunction(string $property) : string
3737
{
3838
return 'get'. to_camel_case($property) . 'Property';
3939
}
4040

41-
protected function callPropertyFunction($property, $value)
41+
protected function callPropertyFunction(string $property, $value)
4242
{
4343
if ($this->isPropertyNeedProcess($property)) {
4444
return call_user_func_array([$this, $this->getPropertyFunction($property)], [$value]);
@@ -47,12 +47,12 @@ protected function callPropertyFunction($property, $value)
4747
return $value;
4848
}
4949

50-
public function getProperty($property)
50+
public function getProperty(string $property)
5151
{
5252
return get_from_array($this->data, $property);
5353
}
5454

55-
public function getData()
55+
public function getData() : array
5656
{
5757
return $this->generatedData;
5858
}

0 commit comments

Comments
 (0)