From 0765d2b453ee943ca75c275580351144517fb6ae Mon Sep 17 00:00:00 2001
From: Ilyas Salikhov <salikhoff@gmail.com>
Date: Tue, 30 Jan 2024 18:39:44 +0300
Subject: [PATCH] Compability with PHP 8.1 (string functions calling)

---
 Annotation/ApiDoc.php           | 2 +-
 Extractor/ApiDocExtractor.php   | 4 ++--
 Formatter/AbstractFormatter.php | 2 +-
 Formatter/SwaggerFormatter.php  | 2 +-
 Util/DocCommentExtractor.php    | 2 +-
 5 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/Annotation/ApiDoc.php b/Annotation/ApiDoc.php
index 6e999a2..f4fe075 100644
--- a/Annotation/ApiDoc.php
+++ b/Annotation/ApiDoc.php
@@ -526,7 +526,7 @@ class ApiDoc
 
             //replace route placeholders
             foreach ($route->getDefaults() as $key => $value) {
-                if (is_string($value)) {
+                if (null !== $this->host && is_string($value)) {
                     $this->host = str_replace('{' . $key . '}', $value, $this->host);
                 }
             }
diff --git a/Extractor/ApiDocExtractor.php b/Extractor/ApiDocExtractor.php
index d347db6..222701c 100644
--- a/Extractor/ApiDocExtractor.php
+++ b/Extractor/ApiDocExtractor.php
@@ -149,7 +149,7 @@ class ApiDocExtractor
                             $resources[] = $resource;
                         } else {
                             // remove format from routes used for resource grouping
-                            $resources[] = str_replace('.{_format}', '', $route->getPath());
+                            $resources[] = str_replace('.{_format}', '', $route->getPath() ?: '');
                         }
                     }
 
@@ -168,7 +168,7 @@ class ApiDocExtractor
         rsort($resources);
         foreach ($array as $index => $element) {
             $hasResource = false;
-            $path        = $element['annotation']->getRoute()->getPath();
+            $path        = $element['annotation']->getRoute()->getPath() ?: '';
 
             foreach ($resources as $resource) {
                 if (0 === strpos($path, $resource) || $resource === $element['annotation']->getResource()) {
diff --git a/Formatter/AbstractFormatter.php b/Formatter/AbstractFormatter.php
index 981e294..7676e73 100644
--- a/Formatter/AbstractFormatter.php
+++ b/Formatter/AbstractFormatter.php
@@ -173,7 +173,7 @@ abstract class AbstractFormatter implements FormatterInterface
             }
         }
 
-        $annotation['id'] = strtolower($annotation['method']).'-'.str_replace('/', '-', $annotation['uri']);
+        $annotation['id'] = strtolower($annotation['method'] ?? '').'-'.str_replace('/', '-', $annotation['uri'] ?? '');
 
         return $annotation;
     }
diff --git a/Formatter/SwaggerFormatter.php b/Formatter/SwaggerFormatter.php
index 2de44ed..46082e5 100644
--- a/Formatter/SwaggerFormatter.php
+++ b/Formatter/SwaggerFormatter.php
@@ -594,6 +594,6 @@ class SwaggerFormatter implements FormatterInterface
         $resource = preg_replace('#/^#', '', $resource);
         $resource = $this->normalizeResourcePath($resource);
 
-        return sprintf('%s_%s', strtolower($method), $resource);
+        return sprintf('%s_%s', strtolower($method ?: ''), $resource);
     }
 }
diff --git a/Util/DocCommentExtractor.php b/Util/DocCommentExtractor.php
index a06a587..1ea3862 100644
--- a/Util/DocCommentExtractor.php
+++ b/Util/DocCommentExtractor.php
@@ -10,7 +10,7 @@ class DocCommentExtractor
      */
     public function getDocComment(\Reflector $reflected)
     {
-        $comment = $reflected->getDocComment();
+        $comment = $reflected->getDocComment() ?? '';
 
         // let's clean the doc block
         $comment = str_replace('/**', '', $comment);