Skip to content

Commit

Permalink
chore: move adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
DeepDiver1975 committed Sep 19, 2023
1 parent 98e0eeb commit 429a31f
Show file tree
Hide file tree
Showing 12 changed files with 150 additions and 132 deletions.
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@
"ext-gd": "*",
"ext-pdo": "*",
"ext-libxml": "*",
"ext-simplexml": "*"
"ext-simplexml": "*",
"ext-fileinfo": "*",
"ext-exif": "*"
},
"extra": {
"bamarni-bin": {
Expand Down
24 changes: 10 additions & 14 deletions lib/private/Image/BmpToResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ class BmpToResource {
/** @var string[][] $pixelArray */
private $pixelArray;

/** @var resource $resource */
private $resource;
private \GdImage $resource;

/** @var array $bytesPerDepth */
private $bytesPerDepth = [
Expand Down Expand Up @@ -87,10 +86,11 @@ public function toResource() {
$this->pixelArray = $this->readPixelArray();

// create gd image
$this->resource = \imagecreatetruecolor($this->header['width'], $this->header['height']);
if ($this->resource === false) {
$resource = \imagecreatetruecolor($this->header['width'], $this->header['height']);
if ($resource === false) {
throw new \RuntimeException('imagecreatetruecolor failed for file ' . $this->getFilename() . '" with dimensions ' . $this->header['width'] . 'x' . $this->header['height']);
}
$this->resource = $resource;

$this->pixelArrayToImage();
} catch (\Exception $e) {
Expand Down Expand Up @@ -149,7 +149,7 @@ private function readDibHeader() {
}

$validBitDepth = \array_keys($this->bytesPerDepth);
if (!\in_array($dibHeader['bits'], $validBitDepth)) {
if (!\in_array($dibHeader['bits'], $validBitDepth, true)) {
throw new \UnexpectedValueException('Bit Depth ' . $dibHeader['bits'] . ' in ' . $this->getFilename() . ' is not supported');
}

Expand All @@ -159,7 +159,7 @@ private function readDibHeader() {
private function fixImageSize($header) {
// No compression - calculate it in our own
if ($header['compression'] === self::COMPRESSION_BI_RGB) {
$bytesPerRow = \intval(\floor(($header['bits'] * $header['width'] + 31) / 32) * 4);
$bytesPerRow = (int)(\floor(($header['bits'] * $header['width'] + 31) / 32) * 4);
$imageSize = $bytesPerRow * \abs($header['height']);
} else {
$imageSize = $this->file->getSize() - $this->header['offset'];
Expand Down Expand Up @@ -196,7 +196,7 @@ private function readPixelArray() {
$this->file->fseek($this->header['offset'], SEEK_SET);
$pixelString = $this->readFile($this->header['imagesize']);

$bytesPerRow = \intval(\floor(($this->header['bits'] * $this->header['width'] + 31) / 32) * 4);
$bytesPerRow = (int)(\floor(($this->header['bits'] * $this->header['width'] + 31) / 32) * 4);
$plainPixelArray = \str_split($pixelString, $bytesPerRow);

// Positive height: Bottom row first.
Expand All @@ -212,10 +212,7 @@ private function readPixelArray() {
return $pixelArray;
}

/**
* @return resource
*/
private function pixelArrayToImage() {
private function pixelArrayToImage(): \GdImage {
$x = 0;
$y = 0;
foreach ($this->pixelArray as $pixelRow) {
Expand Down Expand Up @@ -246,7 +243,7 @@ private function pixelArrayToImage() {
private function getColors($raw) {
$extra = \chr(0); // used to complement an argument to word or double word
$colors = [];
if (\in_array($this->header['bits'], [32, 24])) {
if (\in_array($this->header['bits'], [32, 24], true)) {
$colors = @\unpack('V', $raw . $extra);
} elseif ($this->header['bits'] === 16) {
$colors = @\unpack('v', $raw);
Expand All @@ -264,8 +261,7 @@ function ($i) {
);
}

$colors = \array_values($colors);
return $colors;
return \array_values($colors);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion lib/private/IntegrityCheck/Checker.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,8 @@ public function getResults() {
return \json_decode($cachedResults, true);
}

return \json_decode($this->getAppValue(self::CACHE_KEY, '{}'), true);
$v = $this->getAppValue(self::CACHE_KEY, '{}') ?? '{}';
return \json_decode($v, true);
}

/**
Expand Down
34 changes: 19 additions & 15 deletions lib/private/Memcache/APCu.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ class APCu extends Cache implements IMemcache {

use CADTrait;

public function get($key) {
public function get($key): mixed {
$result = \apcu_fetch($this->getPrefix() . $key, $success);
if (!$success) {
return null;
}
return $result;
}

public function set($key, $value, $ttl = 0) {
public function set($key, $value, $ttl = 0): mixed {
return \apcu_store($this->getPrefix() . $key, $value, $ttl);
}

Expand Down Expand Up @@ -109,32 +109,36 @@ public function dec($key, $step = 1) {
* @param mixed $new
* @return bool
*/
public function cas($key, $old, $new) {
public function cas($key, $old, $new): bool {
// apc only does cas for ints
if (\is_int($old) and \is_int($new)) {
if (\is_int($old) && \is_int($new)) {
return \apcu_cas($this->getPrefix() . $key, $old, $new);
} else {
return $this->casEmulated($key, $old, $new);
}

return $this->casEmulated($key, $old, $new);
}

/**
* @return bool
*/
public static function isAvailable() {
public static function isAvailable(): bool {
if (!\extension_loaded('apcu')) {
return false;
} elseif (!\OC::$server->getIniWrapper()->getBool('apc.enabled')) {
}

if (!\OC::$server->getIniWrapper()->getBool('apc.enabled')) {
return false;
} elseif (!\OC::$server->getIniWrapper()->getBool('apc.enable_cli') && \OC::$CLI) {
}

if (!\OC::$server->getIniWrapper()->getBool('apc.enable_cli') && \OC::$CLI) {
return false;
} elseif (
\version_compare(\phpversion('apc'), '4.0.6') === -1 &&
\version_compare(\phpversion('apcu'), '5.1.0') === -1
) {
}

if (\version_compare(\phpversion('apc'), '4.0.6') === -1 &&
\version_compare(\phpversion('apcu'), '5.1.0') === -1) {
return false;
} else {
return true;
}

return true;
}
}
8 changes: 5 additions & 3 deletions lib/private/Memcache/NullCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@

namespace OC\Memcache;

class NullCache extends Cache implements \OCP\IMemcache {
public function get($key) {
use OCP\IMemcache;

class NullCache extends Cache implements IMemcache {
public function get($key): mixed {
return null;
}

public function set($key, $value, $ttl = 0) {
public function set($key, $value, $ttl = 0): mixed {
return true;
}

Expand Down
12 changes: 6 additions & 6 deletions lib/private/Memcache/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,21 @@ protected function getNameSpace() {
return $this->prefix;
}

public function get($key) {
public function get($key): mixed {
$result = self::$cache->get($this->getNameSpace() . $key);
if ($result === false && !self::$cache->exists($this->getNameSpace() . $key)) {
return null;
} else {
return \json_decode($result, true);
}

return \json_decode($result, true);
}

public function set($key, $value, $ttl = 0) {
public function set($key, $value, $ttl = 0): mixed {
if ($ttl > 0) {
return self::$cache->setex($this->getNameSpace() . $key, $ttl, \json_encode($value));
} else {
return self::$cache->set($this->getNameSpace() . $key, \json_encode($value));
}

return self::$cache->set($this->getNameSpace() . $key, \json_encode($value));
}

public function hasKey($key) {
Expand Down

0 comments on commit 429a31f

Please sign in to comment.