Skip to content

Commit

Permalink
Merge pull request #9 from easybill/pr/code-cleanup-and-refactor
Browse files Browse the repository at this point in the history
Code cleanups, refactor etc.
  • Loading branch information
PATROMO authored Jan 21, 2020
2 parents 9294b55 + 88714d3 commit 6283d1b
Show file tree
Hide file tree
Showing 10 changed files with 395 additions and 422 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
],
"require": {
"php": "^7.2",
"jms/serializer": "^3.4"
"jms/serializer": "^3.4",
"ext-dom": "*"
},
"require-dev": {
"phpunit/phpunit": "^8"
Expand Down
5 changes: 3 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/Easybill/ZUGFeRD/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@
namespace Easybill\ZUGFeRD;

use Easybill\ZUGFeRD\Model\Document;
use JMS\Serializer\Serializer;
use JMS\Serializer\SerializerBuilder;
use JMS\Serializer\SerializerInterface;

class Builder
{

private $serializer;

function __construct(Serializer $serializer)
public function __construct(SerializerInterface $serializer)
{
$this->serializer = $serializer;
}

public function getXML(Document $document)
public function getXML(Document $document): string
{
return $this->serializer->serialize($document, 'xml');
}

public static function create()
public static function create(): Builder
{
$serializer = SerializerBuilder::create()
->setDebug(true)
Expand Down
14 changes: 3 additions & 11 deletions src/Easybill/ZUGFeRD/Helper/UnitCodeHelper.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
<?php

namespace Easybill\ZUGFeRD\Helper;

use Easybill\ZUGFeRD\Model\UnitCode;

/**
* Class UnitCodeHelper
*/
class UnitCodeHelper
{

/**
* @param string $rawString
*
* @return string
*/
public static function getUnitCode($rawString = '')
public static function getUnitCode(string $rawString = ''): string
{
switch(strtolower($rawString)) {
switch (strtolower($rawString)) {
case 'box':
case 'kiste':
$unit = UnitCode::BOX;
Expand Down
15 changes: 5 additions & 10 deletions src/Easybill/ZUGFeRD/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,24 @@
namespace Easybill\ZUGFeRD;

use Easybill\ZUGFeRD\Model\Document;
use JMS\Serializer\Serializer;
use JMS\Serializer\SerializerBuilder;
use JMS\Serializer\SerializerInterface;

class Reader
{
private $serializer;

function __construct(Serializer $serializer)
public function __construct(SerializerInterface $serializer)
{
$this->serializer = $serializer;
}

/**
* @param $xml
*
* @return mixed|Document
*/
public function getDocument($xml)
public function getDocument(string $xml): Document
{
return $this->serializer->deserialize($xml, 'Easybill\ZUGFeRD\Model\Document', 'xml');
return $this->serializer->deserialize($xml, Document::class, 'xml');
}

public static function create()
public static function create(): Reader
{
$serializer = SerializerBuilder::create()
->setDebug(true)
Expand Down
6 changes: 1 addition & 5 deletions src/Easybill/ZUGFeRD/SchemaValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@ class SchemaValidator

/**
* Validates the given XML-string against the ZUGFeRD XSD-files.
*
* @param string $xml
*
* @return bool
*/
public static function isValid($xml)
public static function isValid(string $xml): bool
{
$xmlValidate = new \DOMDocument();
$xmlValidate->loadXML($xml);
Expand Down
Loading

0 comments on commit 6283d1b

Please sign in to comment.