PerformScan: Extract findExposeActionRecord()

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: Ia4ee080ad5423a25a48987a1ccf186c54796c0de
diff --git a/src/PerformScan.cpp b/src/PerformScan.cpp
index b22ada7..cff9da0 100644
--- a/src/PerformScan.cpp
+++ b/src/PerformScan.cpp
@@ -327,6 +327,23 @@
     return false;
 }
 
+static std::optional<std::vector<std::string>::iterator>
+    findExposeActionRecord(std::vector<std::string>& matches,
+                           const nlohmann::json& exposedObject)
+{
+    auto matchIt =
+        std::find_if(matches.begin(), matches.end(),
+                     [name = (exposedObject)["Name"].get<std::string>()](
+                         const std::string& s) { return s == name; });
+
+    if (matchIt == matches.end())
+    {
+        return std::nullopt;
+    }
+
+    return matchIt;
+}
+
 void PerformScan::run()
 {
     boost::container::flat_set<std::string> dbusProbeInterfaces;
@@ -545,18 +562,14 @@
 
                                 for (auto& exposedObject : *configListFind)
                                 {
-                                    auto matchIt = std::find_if(
-                                        matches.begin(), matches.end(),
-                                        [name = (exposedObject)["Name"]
-                                                    .get<std::string>()](
-                                            const std::string& s) {
-                                            return s == name;
-                                        });
-                                    if (matchIt == matches.end())
+                                    auto match = findExposeActionRecord(
+                                        matches, exposedObject);
+                                    if (!match)
                                     {
                                         continue;
                                     }
-                                    foundMatches.insert(*matchIt);
+
+                                    foundMatches.insert(**match);
 
                                     if (isBind)
                                     {