Skip to content

Commit

Permalink
type cast needed for php 8.1 support
Browse files Browse the repository at this point in the history
  • Loading branch information
srjlewis committed Nov 3, 2021
1 parent 7c9a962 commit 9d1f248
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/JsonRPC/Smd/SmdBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

namespace JsonRPC\Smd;


use ReflectionClass;
use ReflectionFunction;
use ReflectionMethod;
Expand Down Expand Up @@ -112,7 +111,8 @@ public function withServices($services)
* @return false|string|array
* @throws \ReflectionException
*/
public function build($target, $returnJSON = true) {
public function build($target, $returnJSON = true)
{
$smd = array(
'envelope' => 'JSON-RPC-2.0',
'transport' => 'POST',
Expand All @@ -130,7 +130,7 @@ public function build($target, $returnJSON = true) {
* ======================
*/
foreach ($this->callbacks as $procedure => $callback) {
if(!isset($smd['services'][$procedure])) {
if (!isset($smd['services'][$procedure])) {
$smd['services'][$procedure] = $this->buildSmdService($procedure, new ReflectionFunction($callback));
}
}
Expand All @@ -141,14 +141,13 @@ public function build($target, $returnJSON = true) {
* ======================
*/
foreach ($this->classes as $procedure => $callback) {
if(!isset($smd['services'][$procedure]) && method_exists($callback[0], $callback[1])) {
if (!isset($smd['services'][$procedure]) && method_exists($callback[0], $callback[1])) {
$className = is_object($callback[0]) ? get_class($callback[0]) : $callback[0];
$methodReflection = (new ReflectionClass($className))->getMethod($callback[1]);

if(!isset($smd['services'][$procedure])){
if (!isset($smd['services'][$procedure])) {
$smd['services'][$procedure] = $this->buildSmdService($procedure, $methodReflection);
}

}
}

Expand All @@ -164,7 +163,7 @@ public function build($target, $returnJSON = true) {
foreach ($classReflection->getMethods(ReflectionMethod::IS_PUBLIC) as $methodReflection) {
if (substr($methodReflection->name, 0, 1) !== '_' && !$methodReflection->isInternal()) {
$serviceName = $namespace . '.' . $methodReflection->getName();
if(!isset($smd['services'][$serviceName])){
if (!isset($smd['services'][$serviceName])) {
$smd['services'][$serviceName] = $this->buildSmdService($serviceName, $methodReflection);
}
}
Expand All @@ -182,15 +181,15 @@ public function build($target, $returnJSON = true) {

foreach ($classReflection->getMethods(ReflectionMethod::IS_PUBLIC) as $methodReflection) {
$serviceName = $methodReflection->getName();
if(!isset($smd['services'][$serviceName])){
if (!isset($smd['services'][$serviceName])) {
$smd['services'][$serviceName] = $this->buildSmdService($serviceName, $methodReflection);
}
}
}

$smd['methods'] = $smd['services'];

if($returnJSON){
if ($returnJSON) {
return json_encode($smd);
}
return $smd;
Expand All @@ -212,7 +211,7 @@ protected function buildSmdService($name, $reflection)
$docBlock = new DocBlock($reflection->getDocComment());
if ($params = $docBlock->tag('param')) {
foreach ($params as $param) {
if (substr($param['var'], 0, 1) === '$') {
if (substr((string)$param['var'], 0, 1) === '$') {
$varName = substr($param['var'], 1);
$paramDocTypes[$varName] = $this->checkTypes(explode('|', $param['type']));
if (count($paramDocTypes[$varName]) === 1) {
Expand Down Expand Up @@ -297,12 +296,11 @@ protected function checkTypes($types)
$returnTypes[] = strtolower($type);
} elseif (class_exists($type)) {
$returnTypes[] = 'object';
}
else {
} else {
$returnTypes[] = 'any';
}
}

return array_unique($returnTypes);
}
}
}

0 comments on commit 9d1f248

Please sign in to comment.