Youtube icon indicating copy to clipboard operation
Youtube copied to clipboard

Warning: Undefined property: stdClass::$items

Open n2ref opened this issue 1 year ago • 2 comments

Warning: Undefined property: stdClass::$items in

/vendor/alaouy/youtube/src/Youtube.php on line 644

Now

    public function decodeSingle(&$apiData)
    {
        $resObj = json_decode($apiData);
        if (isset($resObj->error)) {
            $msg = "Error " . $resObj->error->code . " " . $resObj->error->message;
            if (isset($resObj->error->errors[0])) {
                $msg .= " : " . $resObj->error->errors[0]->reason;
            }

            throw new \Exception($msg);
        } else {
            $itemsArray = $resObj->items;
            if (!is_array($itemsArray) || count($itemsArray) == 0) {
                return false;
            } else {
                return $itemsArray[0];
            }
        }
    }

Need

    public function decodeSingle(&$apiData)
    {
        $resObj = json_decode($apiData);
        
        if (isset($resObj->error)) {
            $msg = "Error " . $resObj->error->code . " " . $resObj->error->message;
            
            if (isset($resObj->error->errors[0])) {
                $msg .= " : " . $resObj->error->errors[0]->reason;
            }

            throw new \Exception($msg);
            
        } else {
            $itemsArray = isset($resObj->items) 
                ? $resObj->items 
                : null;
            
            if ( ! is_array($itemsArray) || count($itemsArray) == 0) {
                return false;
            } else {
                return isset($itemsArray[0]) ? $itemsArray[0] : false;
            }
        }
    }

n2ref avatar Sep 19 '23 15:09 n2ref

@shabuninil Pull requests with tests are always welcome ;)

alaouy avatar Sep 19 '23 18:09 alaouy

Is this a change in the API, should I downgrade or something until a fix is in place?

andach-andreas avatar Nov 09 '23 11:11 andach-andreas