More type fixes

This commit is contained in:
Dennis Eichhorn 2018-07-14 22:58:44 +02:00
parent 2fdc68e7e6
commit 67490f42e6
5 changed files with 48 additions and 26 deletions

View File

@ -36,35 +36,39 @@ final class Rest
*/
public static function request(Request $request) : string
{
$curl = curl_init();
$curl = \curl_init();
if ($curl === false) {
throw new \Exception();
}
switch ($request->getMethod()) {
case RequestMethod::PUT:
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT');
\curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT');
break;
case RequestMethod::DELETE:
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE');
\curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE');
break;
}
if ($request->getMethod() !== RequestMethod::GET) {
curl_setopt($curl, CURLOPT_POST, 1);
\curl_setopt($curl, CURLOPT_POST, 1);
if ($request->getData() !== null) {
curl_setopt($curl, CURLOPT_POSTFIELDS, $request->getData());
\curl_setopt($curl, CURLOPT_POSTFIELDS, $request->getData());
}
}
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, 'username:password');
\curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
\curl_setopt($curl, CURLOPT_USERPWD, 'username:password');
curl_setopt($curl, CURLOPT_URL, $request->__toString());
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
\curl_setopt($curl, CURLOPT_URL, $request->__toString());
\curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
$result = \curl_exec($curl);
curl_close($curl);
\curl_close($curl);
return $result;
return $result === false ? '' : $result;
}
}

View File

@ -85,7 +85,9 @@ final class InfoManager
throw new PathException($this->path);
}
$this->info = \json_decode(file_get_contents($this->path), true);
$contents = \file_get_contents($this->path . '/info.json');
$info = \json_decode($contents === false ? '[]' : $contents, true);
$this->info = $info === false ? [] : $info;
}
/**

View File

@ -210,8 +210,9 @@ final class ModuleManager
// throw new PathException($path);
}
$json = \json_decode(file_get_contents($path), true);
$this->active[$json['name']['internal']] = $json;
$content = \file_get_contents($path);
$json = \json_decode($content === false ? '[]' : $content, true);
$this->active[$json['name']['internal']] = $json === false ? [] : $json;
}
break;
default:
@ -260,8 +261,9 @@ final class ModuleManager
// throw new PathException($path);
}
$json = \json_decode(file_get_contents($path), true);
$this->all[$json['name']['internal']] = $json;
$content = \file_get_contents($path);
$json = \json_decode($content === false ? '[]' : $content, true);
$this->all[$json['name']['internal']] = $json === false ? [] : $json;
}
}
@ -306,8 +308,9 @@ final class ModuleManager
// throw new PathException($path);
}
$json = \json_decode(file_get_contents($path), true);
$this->installed[$json['name']['internal']] = $json;
$content = \file_get_contents($path);
$json = \json_decode($content === false ? '[]' : $content, true);
$this->installed[$json['name']['internal']] = $json === false ? [] : $json;
}
break;
@ -330,7 +333,7 @@ final class ModuleManager
*/
private function loadInfo(string $module) : InfoManager
{
$path = realpath($oldPath = $this->modulePath . '/' . $module . '/info.json');
$path = \realpath($oldPath = $this->modulePath . '/' . $module . '/info.json');
if ($path === false) {
throw new PathException($oldPath);

View File

@ -109,7 +109,9 @@ final class PackageManager
throw new PathException($this->extractPath);
}
$this->info = \json_decode(file_get_contents($this->extractPath . '/info.json'), true);
$contents = \file_get_contents($this->extractPath . '/info.json');
$info = \json_decode($contents === false ? '[]' : $contents, true);
$this->info = $info === false ? [] : $info;
}
/**
@ -121,7 +123,8 @@ final class PackageManager
*/
public function isValid() : bool
{
return $this->authenticate(file_get_contents($this->extractPath . '/package.cert'), $this->hashFiles());
$contents = \file_get_contents($this->extractPath . '/package.cert');
return $this->authenticate($contents === false ? '' : $contents, $this->hashFiles());
}
/**
@ -141,10 +144,15 @@ final class PackageManager
continue;
}
\sodium_crypto_generichash_update($state, \file_get_contents($this->extractPath . '/package/' . $file));
$contents = \file_get_contents($this->extractPath . '/package/' . $file);
if ($contents === false) {
throw new \Exception();
}
\sodium_crypto_generichash_update($state, $contents);
}
return \sodium_crypto_generichash_final();
return \sodium_crypto_generichash_final($state);
}
/**

View File

@ -104,7 +104,12 @@ final class PhpCode
*/
public static function isDisabled(array $functions) : bool
{
$disabled = ini_get('disable_functions');
$disabled = \ini_get('disable_functions');
if ($disabled === false) {
return true;
}
$disabled = \str_replace(' ', '', $disabled);
$disabled = \explode(',', $disabled);
@ -149,6 +154,6 @@ final class PhpCode
*/
public static function validateFileIntegrity(string $source, string $hash) : bool
{
return md5_file($source) === $hash;
return \md5_file($source) === $hash;
}
}