-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from dfridrich/1.0
phpcsfixer
- Loading branch information
Showing
5 changed files
with
47 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,13 +8,12 @@ | |
use Defr\Ares\TaxRecord; | ||
|
||
/** | ||
* Class Ares | ||
* @package Defr | ||
* Class Ares. | ||
* | ||
* @author Dennis Fridrich <[email protected]> | ||
*/ | ||
class Ares | ||
{ | ||
|
||
const URL_BAS = 'http://wwwinfo.mfcr.cz/cgi-bin/ares/darv_bas.cgi?ico=%s'; | ||
const URL_RES = 'http://wwwinfo.mfcr.cz/cgi-bin/ares/darv_res.cgi?ICO=%s'; | ||
const URL_TAX = 'http://wwwinfo.mfcr.cz/cgi-bin/ares/ares_es.cgi?ico=%s'; | ||
|
@@ -41,30 +40,29 @@ class Ares | |
*/ | ||
public function __construct($cacheDir = null, $debug = false) | ||
{ | ||
|
||
if ($cacheDir === null) { | ||
$cacheDir = sys_get_temp_dir(); | ||
} | ||
|
||
$this->cacheDir = $cacheDir . '/defr/ares'; | ||
$this->cacheDir = $cacheDir.'/defr/ares'; | ||
$this->debug = $debug; | ||
|
||
// Create cache dirs if they doesn't exist | ||
if (!is_dir($this->cacheDir)) { | ||
mkdir($this->cacheDir, 0777, true); | ||
} | ||
|
||
} | ||
|
||
/** | ||
* @param $id | ||
* | ||
* @return AresRecord | ||
* | ||
* @throws \InvalidArgumentException | ||
* @throws Ares\AresException | ||
*/ | ||
public function findByIdentificationNumber($id) | ||
{ | ||
|
||
$id = Lib::toInteger($id); | ||
|
||
if (!is_int($id)) { | ||
|
@@ -74,14 +72,12 @@ public function findByIdentificationNumber($id) | |
// Sestaveni URL | ||
$url = sprintf(self::URL_BAS, $id); | ||
|
||
$cachedFileName = $id . '_' . date($this->cacheStrategy) . '.php'; | ||
$cachedFile = $this->cacheDir . '/bas_' . $cachedFileName; | ||
$cachedRawFile = $this->cacheDir . '/bas_raw_' . $cachedFileName; | ||
$cachedFileName = $id.'_'.date($this->cacheStrategy).'.php'; | ||
$cachedFile = $this->cacheDir.'/bas_'.$cachedFileName; | ||
$cachedRawFile = $this->cacheDir.'/bas_raw_'.$cachedFileName; | ||
|
||
if (!is_file($cachedFile)) { | ||
|
||
try { | ||
|
||
$aresRequest = file_get_contents($url); | ||
if ($this->debug) { | ||
file_put_contents($cachedRawFile, $aresRequest); | ||
|
@@ -94,7 +90,6 @@ public function findByIdentificationNumber($id) | |
$elements = $data->children($ns['D'])->VBAS; | ||
|
||
if (strval($elements->ICO) == $id) { | ||
|
||
$record = new AresRecord(); | ||
|
||
$record->setCompanyId($id); | ||
|
@@ -110,13 +105,12 @@ public function findByIdentificationNumber($id) | |
} | ||
|
||
if (strval($elements->AA->NCO)) { | ||
$record->setTown(strval($elements->AA->N . ' - ' . strval($elements->AA->NCO))); | ||
$record->setTown(strval($elements->AA->N.' - '.strval($elements->AA->NCO))); | ||
} else { | ||
$record->setTown(strval($elements->AA->N)); | ||
} | ||
|
||
$record->setZip(strval($elements->AA->PSC)); | ||
|
||
} else { | ||
throw new AresException('IČ firmy nebylo nalezeno.'); | ||
} | ||
|
@@ -128,27 +122,25 @@ public function findByIdentificationNumber($id) | |
} | ||
|
||
file_put_contents($cachedFile, serialize($record)); | ||
|
||
} else { | ||
|
||
/** @var AresRecord $record */ | ||
$record = unserialize(file_get_contents($cachedFile)); | ||
|
||
} | ||
|
||
return $record; | ||
|
||
} | ||
|
||
/** | ||
* @param $id | ||
* | ||
* @return AresRecord | ||
* | ||
* @throws \InvalidArgumentException | ||
* @throws Ares\AresException | ||
*/ | ||
public function findInResById($id) | ||
{ | ||
|
||
$id = Lib::toInteger($id); | ||
|
||
if (!is_int($id)) { | ||
|
@@ -158,9 +150,9 @@ public function findInResById($id) | |
// Sestaveni URL | ||
$url = sprintf(self::URL_RES, $id); | ||
|
||
$cachedFileName = $id . '_' . date($this->cacheStrategy) . '.php'; | ||
$cachedFile = $this->cacheDir . '/res_' . $cachedFileName; | ||
$cachedRawFile = $this->cacheDir . '/res_raw_' . $cachedFileName; | ||
$cachedFileName = $id.'_'.date($this->cacheStrategy).'.php'; | ||
$cachedFile = $this->cacheDir.'/res_'.$cachedFileName; | ||
$cachedRawFile = $this->cacheDir.'/res_raw_'.$cachedFileName; | ||
|
||
if (!is_file($cachedFile)) { | ||
try { | ||
|
@@ -201,18 +193,18 @@ public function findInResById($id) | |
} | ||
|
||
return $record; | ||
|
||
} | ||
|
||
/** | ||
* @param $id | ||
* | ||
* @return TaxRecord|mixed | ||
* | ||
* @throws \InvalidArgumentException | ||
* @throws \Exception | ||
*/ | ||
public function findVatById($id) | ||
{ | ||
|
||
$id = Lib::toInteger($id); | ||
|
||
if (!is_int($id)) { | ||
|
@@ -222,9 +214,9 @@ public function findVatById($id) | |
// Sestaveni URL | ||
$url = sprintf(self::URL_TAX, $id); | ||
|
||
$cachedFileName = $id . '_' . date($this->cacheStrategy) . '.php'; | ||
$cachedFile = $this->cacheDir . '/tax_' . $cachedFileName; | ||
$cachedRawFile = $this->cacheDir . '/tax_raw_' . $cachedFileName; | ||
$cachedFileName = $id.'_'.date($this->cacheStrategy).'.php'; | ||
$cachedFile = $this->cacheDir.'/tax_'.$cachedFileName; | ||
$cachedRawFile = $this->cacheDir.'/tax_raw_'.$cachedFileName; | ||
|
||
if (!is_file($cachedFile)) { | ||
try { | ||
|
@@ -257,19 +249,19 @@ public function findVatById($id) | |
} | ||
|
||
return $record; | ||
|
||
} | ||
|
||
/** | ||
* @param $name | ||
* @param null $city | ||
* | ||
* @return array|AresRecords | ||
* | ||
* @throws \InvalidArgumentException | ||
* @throws \Exception | ||
*/ | ||
public function findByName($name, $city = null) | ||
{ | ||
|
||
if (strlen($name) < 3) { | ||
throw new \InvalidArgumentException('Zadejte minimálně tři znaky pro hledání.'); | ||
} | ||
|
@@ -280,9 +272,9 @@ public function findByName($name, $city = null) | |
urlencode(Lib::stripDiacritics($city)) | ||
); | ||
|
||
$cachedFileName = date($this->cacheStrategy) . '_' . md5($name . $city) . '.php'; | ||
$cachedFile = $this->cacheDir . '/find_' . $cachedFileName; | ||
$cachedRawFile = $this->cacheDir . '/find_raw_' . $cachedFileName; | ||
$cachedFileName = date($this->cacheStrategy).'_'.md5($name.$city).'.php'; | ||
$cachedFile = $this->cacheDir.'/find_'.$cachedFileName; | ||
$cachedRawFile = $this->cacheDir.'/find_raw_'.$cachedFileName; | ||
|
||
if (!is_file($cachedFile)) { | ||
try { | ||
|
@@ -324,7 +316,6 @@ public function findByName($name, $city = null) | |
} | ||
|
||
return $records; | ||
|
||
} | ||
|
||
/** | ||
|
@@ -336,11 +327,10 @@ public function setCacheStrategy($cacheStrategy) | |
} | ||
|
||
/** | ||
* @param boolean $debug | ||
* @param bool $debug | ||
*/ | ||
public function setDebug($debug) | ||
{ | ||
$this->debug = $debug; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,11 +3,10 @@ | |
namespace Defr\Ares; | ||
|
||
/** | ||
* Class AresException | ||
* @package Defr\Ares | ||
* Class AresException. | ||
* | ||
* @author Dennis Fridrich <[email protected]> | ||
*/ | ||
class AresException extends \Exception | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,13 +3,12 @@ | |
namespace Defr\Ares; | ||
|
||
/** | ||
* Class AresRecord | ||
* @package Defr\Ares | ||
* Class AresRecord. | ||
* | ||
* @author Dennis Fridrich <[email protected]> | ||
*/ | ||
class AresRecord | ||
{ | ||
|
||
public $companyId; | ||
public $taxId; | ||
public $companyName; | ||
|
@@ -72,10 +71,10 @@ public function setStreetOrientationNumber($streetOrientationNumber) | |
*/ | ||
public function getStreetWithNumbers() | ||
{ | ||
return $this->street . ' ' | ||
. ($this->streetOrientationNumber | ||
return $this->street.' ' | ||
.($this->streetOrientationNumber | ||
? | ||
$this->streetHouseNumber . '/' . $this->streetOrientationNumber | ||
$this->streetHouseNumber.'/'.$this->streetOrientationNumber | ||
: | ||
$this->streetHouseNumber); | ||
} | ||
|
@@ -167,5 +166,4 @@ public function getZip() | |
{ | ||
return $this->zip; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,16 +3,15 @@ | |
namespace Defr\Ares; | ||
|
||
/** | ||
* Class AresRecords | ||
* @package Defr\Ares | ||
* Class AresRecords. | ||
* | ||
* @author Dennis Fridrich <[email protected]> | ||
*/ | ||
class AresRecords implements \ArrayAccess, \IteratorAggregate | ||
{ | ||
public $array = array(); | ||
|
||
public $array = Array(); | ||
|
||
function offsetExists($offset) | ||
public function offsetExists($offset) | ||
{ | ||
if (isset($this->array[$offset])) { | ||
return true; | ||
|
@@ -23,9 +22,10 @@ function offsetExists($offset) | |
|
||
/** | ||
* @param mixed $offset | ||
* | ||
* @return bool|AresRecord | ||
*/ | ||
function offsetGet($offset) | ||
public function offsetGet($offset) | ||
{ | ||
if ($this->offsetExists($offset)) { | ||
return $this->array[$offset]; | ||
|
@@ -34,7 +34,7 @@ function offsetGet($offset) | |
} | ||
} | ||
|
||
function offsetSet($offset, $value) | ||
public function offsetSet($offset, $value) | ||
{ | ||
if ($offset) { | ||
$this->array[$offset] = $value; | ||
|
@@ -43,14 +43,13 @@ function offsetSet($offset, $value) | |
} | ||
} | ||
|
||
function offsetUnset($offset) | ||
public function offsetUnset($offset) | ||
{ | ||
unset($this->array[$offset]); | ||
} | ||
|
||
function getIterator() | ||
public function getIterator() | ||
{ | ||
return new \ArrayIterator($this->array); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,13 +3,12 @@ | |
namespace Defr\Ares; | ||
|
||
/** | ||
* Class TaxRecord | ||
* @package Defr\Ares | ||
* Class TaxRecord. | ||
* | ||
* @author Dennis Fridrich <[email protected]> | ||
*/ | ||
class TaxRecord | ||
{ | ||
|
||
public $taxId = null; | ||
|
||
/** | ||
|
@@ -27,5 +26,4 @@ public function __toString() | |
{ | ||
return strval($this->taxId); | ||
} | ||
|
||
} | ||
} |