Skip to content

Commit

Permalink
PhpStan is happy now
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitexus committed Mar 5, 2024
1 parent 85a4293 commit 1d2c718
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
1 change: 1 addition & 0 deletions composer.json
Expand Up @@ -7,6 +7,7 @@
"email": "info@vitexsoftware.cz"
}
],
"license": "MIT",
"minimum-stability": "dev",
"autoload": {
"psr-4": {
Expand Down
46 changes: 33 additions & 13 deletions src/HAR/Har.php
Expand Up @@ -12,14 +12,14 @@ class Har extends \Ease\Brick
/**
* Curl Handle.
*
* @var resource
* @var \CurlHandle
*/
public $curl = null;

/**
* Informace o posledním HTTP requestu.
*
* @var *
* @var array
*/
public $curlInfo;

Expand Down Expand Up @@ -65,32 +65,32 @@ class Har extends \Ease\Brick

/**
*
* @var string
* @var int
*/
private $tileDone;

/**
*
* @var int
* @var float
*/
private $Xes;

/**
*
* @var int
* @var float
*/
private $Yes;

/**
*
* @var type
* @var int
*/
private $z;
private $bigImage;

/**
*
* @var int
* @var float
*/
private $tileCount;

Expand Down Expand Up @@ -124,11 +124,27 @@ public function curlInit()
curl_setopt($this->curl, CURLOPT_VERBOSE, ($this->debug === true)); // For debugging
}

public function addStatusMessage($message, $type = 'info', $addIcons = true)
/**
*
* @param string $message
* @param string $type
* @param mixed $caller
*
* @return bool message shown
*/
public function addStatusMessage($message, $type = 'info', $caller = null)
{
echo date('Y-m-d H:i:s') . ' ' . $message . "\n";
return true;
}

/**
* Perform initial download
*
* @param int $itemId
*
* @return bool was good http response obtained ?
*/
public function loadImagePage($itemId)
{
return $this->doCurlRequest("https://www.himalayanart.org/items/$itemId/images/primary") == 200;
Expand All @@ -143,6 +159,7 @@ public function loadImagePage($itemId)
*/
public function obtain($itemId)
{
$result = null;
if ($this->loadImagePage($itemId)) {
if ($this->debug) {
$this->addStatusMessage('downloading ' . "https://www.himalayanart.org/items/$itemId/images/primary");
Expand Down Expand Up @@ -197,13 +214,14 @@ public function obtain($itemId)
'ItemID: ' . $itemId . ' saved as ' . realpath($this->doneDir . '/' . $itemId . '.png'),
'success'
);
return true;
}
$result = true;
}
} else {
$this->addStatusMessage('Json not found for ' . $itemId, 'warning');
return false;
$result = false;
}
return $result;
}

/**
Expand All @@ -218,6 +236,7 @@ public function obtain($itemId)
*/
public function loadTile($itemId, $x, $y, $baseUrl)
{
$result = false;
$xpos = $x * 256;
$ypos = $y * 256;
$tileUrl = $baseUrl . $this->z . '/' . $x . '_' . $y . '.jpg';
Expand All @@ -240,18 +259,19 @@ public function loadTile($itemId, $x, $y, $baseUrl)
}
};

if (strlen($this->lastResponseCode == 200)) {
if ($this->lastResponseCode == 200) {
file_put_contents($tileTmp, $this->lastCurlResponse);
$tile = imagecreatefromjpeg($tileTmp);
imagecopy($this->bigImage, $tile, $xpos, $ypos, 0, 0, 256, 256);
unlink($tileTmp);
$this->tileDone++;
if ($this->debug) {
$this->addStatusMessage('ItemID: ' . $itemId . ' Row ' . $y . ' of ' . $this->Yes . ' tile ' . $x . ' of ' . $this->Xes . ' (' . $this->tileDone . ' of ' . $this->tileCount . ') ' . basename($tileUrl));
imagepng($this->bigImage, $this->targetImge($itemId));
imagepng($this->bigImage, $this->targetImage($itemId));
}
return true;
$result = true;
}
return $result;
}

/**
Expand Down

0 comments on commit 1d2c718

Please sign in to comment.