Skip to content

Commit 3ddd474

Browse files
authored
Merge pull request #112 from katheroine/issue-111-contract-completing
Issue 111 contract completing
2 parents 05189d0 + 59fa8fa commit 3ddd474

12 files changed

+29
-44
lines changed

src/Coder/Datafile/Decoder.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
* @license http://opensource.org/licenses/MIT MIT License
2929
* @link https://github.com/ExOrg/php-data-coder
3030
*/
31-
class Decoder extends AbstractCoder
31+
class Decoder extends AbstractCoder implements DecodingStrategyInterface
3232
{
3333
use CoderBuildingTrait;
3434

src/Coder/Data/AbstractDecoder.php src/Coder/Datafile/DecodingStrategyInterface.php

+8-11
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,26 @@
1111
* file that was distributed with this source code.
1212
*/
1313

14-
namespace ExOrg\DataCoder\Coder\Data;
14+
namespace ExOrg\DataCoder\Coder\Datafile;
1515

1616
/**
17-
* Abstract Data Decoder.
18-
* Abstract class for Data Decoder
19-
* for concrete data format.
17+
* Datafile Decoding Strategy Interface.
18+
* Defines interface of particular data file decoding strategy.
2019
*
2120
* @package DataCoder
2221
* @author Katarzyna Krasińska <[email protected]>
2322
* @copyright Copyright (c) 2015-2023 Katarzyna Krasińska
2423
* @license http://opensource.org/licenses/MIT MIT License
2524
* @link https://github.com/ExOrg/php-data-coder
2625
*/
27-
abstract class AbstractDecoder
26+
interface DecodingStrategyInterface
2827
{
2928
/**
30-
* Validate data.
29+
* Decode file content.
3130
*
32-
* @param string $data
31+
* @param string $filePath
3332
*
34-
* @return void
33+
* @return array
3534
*/
36-
protected function validateData(string $data): void
37-
{
38-
}
35+
public function decodeFile(string $filePath): array;
3936
}

src/Coder/Datafile/Encoder.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
* @license http://opensource.org/licenses/MIT MIT License
2929
* @link https://github.com/ExOrg/php-data-coder
3030
*/
31-
class Encoder extends AbstractCoder
31+
class Encoder extends AbstractCoder implements EncodingStrategyInterface
3232
{
3333
use CoderBuildingTrait;
3434

src/Coder/Data/AbstractEncoder.php src/Coder/Datafile/EncodingStrategyInterface.php

+7-9
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,27 @@
1111
* file that was distributed with this source code.
1212
*/
1313

14-
namespace ExOrg\DataCoder\Coder\Data;
14+
namespace ExOrg\DataCoder\Coder\Datafile;
1515

1616
/**
17-
* Abstract Data Encoder.
18-
* Abstract class for Data Encoder
19-
* for concrete data format.
17+
* Datafile Encoding Strategy Interface.
18+
* Defines interface of particular data file encoding strategy.
2019
*
2120
* @package DataCoder
2221
* @author Katarzyna Krasińska <[email protected]>
2322
* @copyright Copyright (c) 2015-2023 Katarzyna Krasińska
2423
* @license http://opensource.org/licenses/MIT MIT License
2524
* @link https://github.com/ExOrg/php-data-coder
2625
*/
27-
abstract class AbstractEncoder
26+
interface EncodingStrategyInterface
2827
{
2928
/**
30-
* Validate data.
29+
* Encode data and write to the file.
3130
*
3231
* @param array $data
32+
* @param string $filePath
3333
*
3434
* @return void
3535
*/
36-
protected function validateData(array $data): void
37-
{
38-
}
36+
public function encodeFile(array $data, string $filePath): void;
3937
}

src/Coder/Json/Data/Decoder.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
namespace ExOrg\DataCoder\Coder\Json\Data;
1515

16-
use ExOrg\DataCoder\Coder\Data\AbstractDecoder;
1716
use ExOrg\DataCoder\Coder\Data\DecodingStrategyInterface;
1817
use ExOrg\DataCoder\DataFormat\DataFormatInvalidException;
1918

@@ -27,7 +26,7 @@
2726
* @license http://opensource.org/licenses/MIT MIT License
2827
* @link https://github.com/ExOrg/php-data-coder
2928
*/
30-
class Decoder extends AbstractDecoder implements DecodingStrategyInterface
29+
class Decoder implements DecodingStrategyInterface
3130
{
3231
/**
3332
* Decode given JSON data to PHP array.
@@ -40,8 +39,6 @@ class Decoder extends AbstractDecoder implements DecodingStrategyInterface
4039
*/
4140
public function decodeData(string $data): array
4241
{
43-
$this->validateData($data);
44-
4542
$decodedData = json_decode($data, true);
4643

4744
$parsingSuccessful = !(is_null($decodedData));

src/Coder/Json/Data/Encoder.php

+1-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
namespace ExOrg\DataCoder\Coder\Json\Data;
1515

16-
use ExOrg\DataCoder\Coder\Data\AbstractEncoder;
1716
use ExOrg\DataCoder\Coder\Data\EncodingStrategyInterface;
1817

1918
/**
@@ -26,7 +25,7 @@
2625
* @license http://opensource.org/licenses/MIT MIT License
2726
* @link https://github.com/ExOrg/php-data-coder
2827
*/
29-
class Encoder extends AbstractEncoder implements EncodingStrategyInterface
28+
class Encoder implements EncodingStrategyInterface
3029
{
3130
/**
3231
* Encode given PHP array to JSON data.
@@ -39,10 +38,6 @@ class Encoder extends AbstractEncoder implements EncodingStrategyInterface
3938
*/
4039
public function encodeData(array $data): string
4140
{
42-
$dataTypeIsCorrect = is_array($data);
43-
44-
$this->validateData($data);
45-
4641
$encodedData = json_encode($data, JSON_PRETTY_PRINT);
4742

4843
return $encodedData;

src/Coder/Json/Datafile/Decoder.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace ExOrg\DataCoder\Coder\Json\Datafile;
1515

16+
use ExOrg\DataCoder\Coder\Datafile\DecodingStrategyInterface;
1617
use ExOrg\DataCoder\File\File;
1718
use ExOrg\DataCoder\Coder\Json\Data\Decoder as DataDecoder;
1819

@@ -26,7 +27,7 @@
2627
* @license http://opensource.org/licenses/MIT MIT License
2728
* @link https://github.com/ExOrg/php-data-coder
2829
*/
29-
class Decoder
30+
class Decoder implements DecodingStrategyInterface
3031
{
3132
/**
3233
* Decode file content.

src/Coder/Json/Datafile/Encoder.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace ExOrg\DataCoder\Coder\Json\Datafile;
1515

16+
use ExOrg\DataCoder\Coder\Datafile\EncodingStrategyInterface;
1617
use ExOrg\DataCoder\File\File;
1718
use ExOrg\DataCoder\Coder\Json\Data\Encoder as DataEncoder;
1819

@@ -26,7 +27,7 @@
2627
* @license http://opensource.org/licenses/MIT MIT License
2728
* @link https://github.com/ExOrg/php-data-coder
2829
*/
29-
class Encoder
30+
class Encoder implements EncodingStrategyInterface
3031
{
3132
/**
3233
* Encode JSON data and write to the file.

src/Coder/Yaml/Data/Decoder.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
namespace ExOrg\DataCoder\Coder\Yaml\Data;
1515

16-
use ExOrg\DataCoder\Coder\Data\AbstractDecoder;
1716
use ExOrg\DataCoder\Coder\Data\DecodingStrategyInterface;
1817
use ExOrg\DataCoder\DataFormat\DataFormatInvalidException;
1918
use Symfony\Component\Yaml\Yaml;
@@ -28,7 +27,7 @@
2827
* @license http://opensource.org/licenses/MIT MIT License
2928
* @link https://github.com/ExOrg/php-data-coder
3029
*/
31-
class Decoder extends AbstractDecoder implements DecodingStrategyInterface
30+
class Decoder implements DecodingStrategyInterface
3231
{
3332
/**
3433
* Decode given YAML data to PHP array.
@@ -43,8 +42,6 @@ public function decodeData(string $data): array
4342
{
4443
$this->turnOffErrors();
4544

46-
$this->validateData($data);
47-
4845
$parsedData = Yaml::parse($data);
4946

5047
$parsingSuccessful = ($parsedData !== null);

src/Coder/Yaml/Data/Encoder.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
namespace ExOrg\DataCoder\Coder\Yaml\Data;
1515

16-
use ExOrg\DataCoder\Coder\Data\AbstractEncoder;
1716
use ExOrg\DataCoder\Coder\Data\EncodingStrategyInterface;
1817
use Symfony\Component\Yaml\Yaml;
1918

@@ -27,7 +26,7 @@
2726
* @license http://opensource.org/licenses/MIT MIT License
2827
* @link https://github.com/ExOrg/php-data-coder
2928
*/
30-
class Encoder extends AbstractEncoder implements EncodingStrategyInterface
29+
class Encoder implements EncodingStrategyInterface
3130
{
3231
/**
3332
* Encode given PHP array to YAML data.
@@ -40,8 +39,6 @@ class Encoder extends AbstractEncoder implements EncodingStrategyInterface
4039
*/
4140
public function encodeData(array $data): string
4241
{
43-
$this->validateData($data);
44-
4542
$encodedData = Yaml::dump($data);
4643

4744
return $encodedData;

src/Coder/Yaml/Datafile/Decoder.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace ExOrg\DataCoder\Coder\Yaml\Datafile;
1515

16+
use ExOrg\DataCoder\Coder\Datafile\DecodingStrategyInterface;
1617
use ExOrg\DataCoder\File\File;
1718
use ExOrg\DataCoder\Coder\Yaml\Data\Decoder as DataDecoder;
1819

@@ -26,7 +27,7 @@
2627
* @license http://opensource.org/licenses/MIT MIT License
2728
* @link https://github.com/ExOrg/php-data-coder
2829
*/
29-
class Decoder
30+
class Decoder implements DecodingStrategyInterface
3031
{
3132
/**
3233
* Decode file content.

src/Coder/Yaml/Datafile/Encoder.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace ExOrg\DataCoder\Coder\Yaml\Datafile;
1515

16+
use ExOrg\DataCoder\Coder\Datafile\EncodingStrategyInterface;
1617
use ExOrg\DataCoder\File\File;
1718
use ExOrg\DataCoder\Coder\Yaml\Data\Encoder as DataEncoder;
1819

@@ -26,7 +27,7 @@
2627
* @license http://opensource.org/licenses/MIT MIT License
2728
* @link https://github.com/ExOrg/php-data-coder
2829
*/
29-
class Encoder
30+
class Encoder implements EncodingStrategyInterface
3031
{
3132
/**
3233
* Encode YAML data and write to the file.

0 commit comments

Comments
 (0)