Enable readability-avoid-const-params-in-decls

This check involves explicitly declaring variables const when they're
declared auto, which helps in readability, and makes it more clear that
the variables are const.

Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I71198ea03850384a389a56ad26f2c4a48c75b148
diff --git a/.clang-tidy b/.clang-tidy
index 0a7f665..953c78e 100644
--- a/.clang-tidy
+++ b/.clang-tidy
@@ -267,6 +267,7 @@
 performance-type-promotion-in-math-fn,
 performance-unnecessary-copy-initialization,
 performance-unnecessary-value-param,
+readability-avoid-const-params-in-decls,
 readability-braces-around-statements,
 readability-const-return-type,
 readability-container-size-empty,
diff --git a/http/common.hpp b/http/common.hpp
index 6f6b24c..01e90b2 100644
--- a/http/common.hpp
+++ b/http/common.hpp
@@ -48,7 +48,7 @@
             std::cerr << i << ", ";
         }
         std::cerr << std::endl;
-        for (auto& i : stringParams)
+        for (const std::string& i : stringParams)
         {
             std::cerr << i << ", ";
         }
diff --git a/http/http_connection.hpp b/http/http_connection.hpp
index 84f5c18..0b58e9b 100644
--- a/http/http_connection.hpp
+++ b/http/http_connection.hpp
@@ -99,8 +99,9 @@
             adaptor.set_verify_mode(boost::asio::ssl::verify_peer);
             std::string id = "bmcweb";
 
+            const char* cStr = id.c_str();
             // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
-            auto* idC = reinterpret_cast<const unsigned char*>(id.c_str());
+            const auto* idC = reinterpret_cast<const unsigned char*>(cStr);
             int ret = SSL_set_session_id_context(
                 adaptor.native_handle(), idC,
                 static_cast<unsigned int>(id.length()));
diff --git a/http/routing.hpp b/http/routing.hpp
index 9cd3d7b..9032b14 100644
--- a/http/routing.hpp
+++ b/http/routing.hpp
@@ -68,7 +68,7 @@
     }
 #endif
 
-    size_t getMethods()
+    size_t getMethods() const
     {
         return methodsBitfield;
     }
diff --git a/http/websocket.hpp b/http/websocket.hpp
index 74bce58..eadb276 100644
--- a/http/websocket.hpp
+++ b/http/websocket.hpp
@@ -34,11 +34,11 @@
     Connection& operator=(const Connection&) = delete;
     Connection& operator=(const Connection&&) = delete;
 
-    virtual void sendBinary(const std::string_view msg) = 0;
+    virtual void sendBinary(std::string_view msg) = 0;
     virtual void sendBinary(std::string&& msg) = 0;
-    virtual void sendText(const std::string_view msg) = 0;
+    virtual void sendText(std::string_view msg) = 0;
     virtual void sendText(std::string&& msg) = 0;
-    virtual void close(const std::string_view msg = "quit") = 0;
+    virtual void close(std::string_view msg = "quit") = 0;
     virtual boost::asio::io_context& getIoContext() = 0;
     virtual ~Connection() = default;
 
diff --git a/include/ibm/locks.hpp b/include/ibm/locks.hpp
index 10f0a9a..b39bada 100644
--- a/include/ibm/locks.hpp
+++ b/include/ibm/locks.hpp
@@ -245,7 +245,7 @@
 
     // validate the lock request
 
-    for (auto& lockRecord : lockRequestStructure)
+    for (const auto& lockRecord : lockRequestStructure)
     {
         bool status = isValidLockRequest(lockRecord);
         if (!status)
diff --git a/include/ibm/management_console_rest.hpp b/include/ibm/management_console_rest.hpp
index 876ceb3..e80e727 100644
--- a/include/ibm/management_console_rest.hpp
+++ b/include/ibm/management_console_rest.hpp
@@ -85,7 +85,7 @@
         return;
     }
     std::uintmax_t saveAreaDirSize = 0;
-    for (auto& it : iter)
+    for (const auto& it : iter)
     {
         if (!std::filesystem::is_directory(it, ec))
         {
diff --git a/include/openbmc_dbus_rest.hpp b/include/openbmc_dbus_rest.hpp
index 9233a27..8aab757 100644
--- a/include/openbmc_dbus_rest.hpp
+++ b/include/openbmc_dbus_rest.hpp
@@ -2232,7 +2232,7 @@
                 }
                 std::filesystem::directory_iterator files(loc);
 
-                for (auto& file : files)
+                for (const auto& file : files)
                 {
                     std::ifstream readFile(file.path());
                     if (!readFile.good())
diff --git a/include/random.hpp b/include/random.hpp
index 0e63391..082c4e3 100644
--- a/include/random.hpp
+++ b/include/random.hpp
@@ -29,7 +29,7 @@
         return std::numeric_limits<uint8_t>::min();
     }
 
-    bool error()
+    bool error() const
     {
         return err;
     }
diff --git a/include/sessions.hpp b/include/sessions.hpp
index b445915..85c0cb9 100644
--- a/include/sessions.hpp
+++ b/include/sessions.hpp
@@ -353,7 +353,7 @@
         return authMethodsConfig;
     }
 
-    bool needsWrite()
+    bool needsWrite() const
     {
         return needWrite;
     }
diff --git a/redfish-core/include/error_messages.hpp b/redfish-core/include/error_messages.hpp
index 8aa6ba6..dcca3aa 100644
--- a/redfish-core/include/error_messages.hpp
+++ b/redfish-core/include/error_messages.hpp
@@ -91,7 +91,7 @@
  * @returns Message InternalError formatted to JSON */
 nlohmann::json internalError();
 
-void internalError(crow::Response& res, const bmcweb::source_location location =
+void internalError(crow::Response& res, bmcweb::source_location location =
                                             bmcweb::source_location::current());
 
 /**
diff --git a/redfish-core/include/event_service_manager.hpp b/redfish-core/include/event_service_manager.hpp
index 4fb07ca..ec294ae 100644
--- a/redfish-core/include/event_service_manager.hpp
+++ b/redfish-core/include/event_service_manager.hpp
@@ -555,7 +555,7 @@
         }
     }
 
-    uint64_t getEventSeqNum()
+    uint64_t getEventSeqNum() const
     {
         return eventSeqNum;
     }
@@ -751,7 +751,7 @@
         }
     }
 
-    void updateSubscriptionData()
+    void updateSubscriptionData() const
     {
         persistent_data::EventServiceStore::getInstance()
             .eventServiceConfig.enabled = serviceEnabled;
diff --git a/redfish-core/include/privileges.hpp b/redfish-core/include/privileges.hpp
index f5bc8b6..160816f 100644
--- a/redfish-core/include/privileges.hpp
+++ b/redfish-core/include/privileges.hpp
@@ -260,7 +260,7 @@
     {
         return true;
     }
-    for (auto& requiredPrivileges : operationPrivilegesRequired)
+    for (const auto& requiredPrivileges : operationPrivilegesRequired)
     {
         BMCWEB_LOG_DEBUG << "Checking operation privileges...";
         if (userPrivileges.isSupersetOf(requiredPrivileges))
diff --git a/redfish-core/include/utils/fw_utils.hpp b/redfish-core/include/utils/fw_utils.hpp
index a0758d9..c05f8cb 100644
--- a/redfish-core/include/utils/fw_utils.hpp
+++ b/redfish-core/include/utils/fw_utils.hpp
@@ -68,7 +68,7 @@
             // example functionalFw:
             // v as 2 "/xyz/openbmc_project/software/ace821ef"
             //        "/xyz/openbmc_project/software/230fb078"
-            for (auto& fw : functionalFw)
+            for (const auto& fw : functionalFw)
             {
                 sdbusplus::message::object_path path(fw);
                 std::string leaf = path.filename();
diff --git a/redfish-core/lib/account_service.hpp b/redfish-core/lib/account_service.hpp
index ecc2e9c..8770782 100644
--- a/redfish-core/lib/account_service.hpp
+++ b/redfish-core/lib/account_service.hpp
@@ -185,7 +185,7 @@
 
     nlohmann::json& roleMapArray = jsonResponse[ldapType]["RemoteRoleMapping"];
     roleMapArray = nlohmann::json::array();
-    for (auto& obj : confData.groupRoleList)
+    for (const auto& obj : confData.groupRoleList)
     {
         BMCWEB_LOG_DEBUG << "Pushing the data groupName="
                          << obj.second.groupName << "\n";
@@ -1539,7 +1539,7 @@
                             asyncResp->res.jsonValue["Members"];
                         memberArray = nlohmann::json::array();
 
-                        for (auto& userpath : users)
+                        for (const auto& userpath : users)
                         {
                             std::string user = userpath.first.filename();
                             if (user.empty())
diff --git a/redfish-core/lib/certificate_service.hpp b/redfish-core/lib/certificate_service.hpp
index 34f6770..23e3ead 100644
--- a/redfish-core/lib/certificate_service.hpp
+++ b/redfish-core/lib/certificate_service.hpp
@@ -952,7 +952,7 @@
             }
             nlohmann::json& links =
                 asyncResp->res.jsonValue["Links"]["Certificates"];
-            for (auto& cert : certs)
+            for (const auto& cert : certs)
             {
                 long id = getIDFromURL(cert.first.str);
                 if (id >= 0)
diff --git a/redfish-core/lib/ethernet.hpp b/redfish-core/lib/ethernet.hpp
index e4e5eb9..f4260a8 100644
--- a/redfish-core/lib/ethernet.hpp
+++ b/redfish-core/lib/ethernet.hpp
@@ -450,7 +450,7 @@
         // Check if proper pattern for object path appears
         if (boost::starts_with(objpath.first.str, ipv6PathStart))
         {
-            for (auto& interface : objpath.second)
+            for (const auto& interface : objpath.second)
             {
                 if (interface.first == "xyz.openbmc_project.Network.IP")
                 {
@@ -463,7 +463,7 @@
                     IPv6AddressData& ipv6Address = *it.first;
                     ipv6Address.id =
                         objpath.first.str.substr(ipv6PathStart.size());
-                    for (auto& property : interface.second)
+                    for (const auto& property : interface.second)
                     {
                         if (property.first == "Address")
                         {
@@ -528,7 +528,7 @@
         // Check if proper pattern for object path appears
         if (boost::starts_with(objpath.first.str, ipv4PathStart))
         {
-            for (auto& interface : objpath.second)
+            for (const auto& interface : objpath.second)
             {
                 if (interface.first == "xyz.openbmc_project.Network.IP")
                 {
@@ -541,7 +541,7 @@
                     IPv4AddressData& ipv4Address = *it.first;
                     ipv4Address.id =
                         objpath.first.str.substr(ipv4PathStart.size());
-                    for (auto& property : interface.second)
+                    for (const auto& property : interface.second)
                     {
                         if (property.first == "Address")
                         {
@@ -1782,7 +1782,7 @@
     nlohmann::json& ipv4StaticArray = jsonResponse["IPv4StaticAddresses"];
     ipv4Array = nlohmann::json::array();
     ipv4StaticArray = nlohmann::json::array();
-    for (auto& ipv4Config : ipv4Data)
+    for (const auto& ipv4Config : ipv4Data)
     {
 
         std::string gatewayStr = ipv4Config.gateway;
@@ -1819,7 +1819,7 @@
     nlohmann::json& ipv6AddrPolicyTable =
         jsonResponse["IPv6AddressPolicyTable"];
     ipv6AddrPolicyTable = nlohmann::json::array();
-    for (auto& ipv6Config : ipv6Data)
+    for (const auto& ipv6Config : ipv6Data)
     {
         ipv6Array.push_back({{"Address", ipv6Config.address},
                              {"PrefixLength", ipv6Config.prefixLength},
diff --git a/redfish-core/lib/hypervisor_system.hpp b/redfish-core/lib/hypervisor_system.hpp
index 76032b3..588cf13 100644
--- a/redfish-core/lib/hypervisor_system.hpp
+++ b/redfish-core/lib/hypervisor_system.hpp
@@ -208,7 +208,7 @@
                 IPv4AddressData& ipv4Address = *it.first;
                 if (ifacePair.first == "xyz.openbmc_project.Object.Enable")
                 {
-                    for (auto& property : ifacePair.second)
+                    for (const auto& property : ifacePair.second)
                     {
                         if (property.first == "Enabled")
                         {
@@ -224,7 +224,7 @@
                 }
                 if (ifacePair.first == "xyz.openbmc_project.Network.IP")
                 {
-                    for (auto& property : ifacePair.second)
+                    for (const auto& property : ifacePair.second)
                     {
                         if (property.first == "Address")
                         {
@@ -497,7 +497,7 @@
     nlohmann::json& ipv4StaticArray = jsonResponse["IPv4StaticAddresses"];
     ipv4Array = nlohmann::json::array();
     ipv4StaticArray = nlohmann::json::array();
-    for (auto& ipv4Config : ipv4Data)
+    for (const auto& ipv4Config : ipv4Data)
     {
         if (ipv4Config.isActive)
         {
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp
index 9f40725..aa4d5ec 100644
--- a/redfish-core/lib/log_services.hpp
+++ b/redfish-core/lib/log_services.hpp
@@ -428,7 +428,7 @@
                     if (interfaceMap.first ==
                         "xyz.openbmc_project.Common.Progress")
                     {
-                        for (auto& propertyMap : interfaceMap.second)
+                        for (const auto& propertyMap : interfaceMap.second)
                         {
                             if (propertyMap.first == "Status")
                             {
@@ -467,7 +467,7 @@
                              "xyz.openbmc_project.Time.EpochTime")
                     {
 
-                        for (auto& propertyMap : interfaceMap.second)
+                        for (const auto& propertyMap : interfaceMap.second)
                         {
                             if (propertyMap.first == "Elapsed")
                             {
@@ -564,7 +564,7 @@
                 std::string(boost::algorithm::to_lower_copy(dumpType)) +
                 "/entry/";
 
-            for (auto& objectPath : resp)
+            for (const auto& objectPath : resp)
             {
                 if (objectPath.first.str != dumpEntryPath + entryID)
                 {
@@ -576,17 +576,18 @@
                 uint64_t size = 0;
                 std::string dumpStatus;
 
-                for (auto& interfaceMap : objectPath.second)
+                for (const auto& interfaceMap : objectPath.second)
                 {
                     if (interfaceMap.first ==
                         "xyz.openbmc_project.Common.Progress")
                     {
-                        for (auto& propertyMap : interfaceMap.second)
+                        for (const auto& propertyMap : interfaceMap.second)
                         {
                             if (propertyMap.first == "Status")
                             {
-                                auto status = std::get_if<std::string>(
-                                    &propertyMap.second);
+                                const std::string* status =
+                                    std::get_if<std::string>(
+                                        &propertyMap.second);
                                 if (status == nullptr)
                                 {
                                     messages::internalError(asyncResp->res);
@@ -599,11 +600,11 @@
                     else if (interfaceMap.first ==
                              "xyz.openbmc_project.Dump.Entry")
                     {
-                        for (auto& propertyMap : interfaceMap.second)
+                        for (const auto& propertyMap : interfaceMap.second)
                         {
                             if (propertyMap.first == "Size")
                             {
-                                auto sizePtr =
+                                const uint64_t* sizePtr =
                                     std::get_if<uint64_t>(&propertyMap.second);
                                 if (sizePtr == nullptr)
                                 {
@@ -618,7 +619,7 @@
                     else if (interfaceMap.first ==
                              "xyz.openbmc_project.Time.EpochTime")
                     {
-                        for (auto& propertyMap : interfaceMap.second)
+                        for (const auto& propertyMap : interfaceMap.second)
                         {
                             if (propertyMap.first == "Elapsed")
                             {
@@ -1373,7 +1374,7 @@
                     nlohmann::json& entriesArray =
                         asyncResp->res.jsonValue["Members"];
                     entriesArray = nlohmann::json::array();
-                    for (auto& objectPath : resp)
+                    for (const auto& objectPath : resp)
                     {
                         const uint32_t* id = nullptr;
                         const uint64_t* timestamp = nullptr;
@@ -1382,12 +1383,13 @@
                         const std::string* message = nullptr;
                         const std::string* filePath = nullptr;
                         bool resolved = false;
-                        for (auto& interfaceMap : objectPath.second)
+                        for (const auto& interfaceMap : objectPath.second)
                         {
                             if (interfaceMap.first ==
                                 "xyz.openbmc_project.Logging.Entry")
                             {
-                                for (auto& propertyMap : interfaceMap.second)
+                                for (const auto& propertyMap :
+                                     interfaceMap.second)
                                 {
                                     if (propertyMap.first == "Id")
                                     {
@@ -1439,7 +1441,8 @@
                             else if (interfaceMap.first ==
                                      "xyz.openbmc_project.Common.FilePath")
                             {
-                                for (auto& propertyMap : interfaceMap.second)
+                                for (const auto& propertyMap :
+                                     interfaceMap.second)
                                 {
                                     if (propertyMap.first == "Path")
                                     {
@@ -1536,7 +1539,7 @@
                         const std::string* filePath = nullptr;
                         bool resolved = false;
 
-                        for (auto& propertyMap : resp)
+                        for (const auto& propertyMap : resp)
                         {
                             if (propertyMap.first == "Id")
                             {
@@ -3423,7 +3426,7 @@
                             return;
                         }
 
-                        auto& [tID, c] = postcodes[value];
+                        const auto& [tID, c] = postcodes[value];
                         if (c.empty())
                         {
                             BMCWEB_LOG_INFO << "No found post code data";
diff --git a/redfish-core/lib/managers.hpp b/redfish-core/lib/managers.hpp
index 9a805f0..c69af7e 100644
--- a/redfish-core/lib/managers.hpp
+++ b/redfish-core/lib/managers.hpp
@@ -1214,7 +1214,7 @@
                         }
                         const std::string* current = nullptr;
                         const std::vector<std::string>* supported = nullptr;
-                        for (auto& [key, value] : resp)
+                        for (const auto& [key, value] : resp)
                         {
                             if (key == "Current")
                             {
@@ -1439,7 +1439,7 @@
                         }
                         const std::string* current = nullptr;
                         const std::vector<std::string>* supported = nullptr;
-                        for (auto& [key, value] : r)
+                        for (const auto& [key, value] : r)
                         {
                             if (key == "Current")
                             {
diff --git a/redfish-core/lib/metric_report.hpp b/redfish-core/lib/metric_report.hpp
index f933cd4..89bd8db 100644
--- a/redfish-core/lib/metric_report.hpp
+++ b/redfish-core/lib/metric_report.hpp
@@ -22,7 +22,7 @@
 {
     nlohmann::json metricValues = nlohmann::json::array_t();
 
-    for (auto& [id, metadata, sensorValue, timestamp] : readings)
+    for (const auto& [id, metadata, sensorValue, timestamp] : readings)
     {
         metricValues.push_back({
             {"MetricId", id},
diff --git a/redfish-core/lib/metric_report_definition.hpp b/redfish-core/lib/metric_report_definition.hpp
index 745fad8..541e631 100644
--- a/redfish-core/lib/metric_report_definition.hpp
+++ b/redfish-core/lib/metric_report_definition.hpp
@@ -86,7 +86,7 @@
     }
 
     nlohmann::json metrics = nlohmann::json::array();
-    for (auto& [sensorPath, operationType, id, metadata] : *readingParams)
+    for (const auto& [sensorPath, operationType, id, metadata] : *readingParams)
     {
         metrics.push_back({
             {"MetricId", id},
diff --git a/redfish-core/lib/sensors.hpp b/redfish-core/lib/sensors.hpp
index 121223e..f3fa52c 100644
--- a/redfish-core/lib/sensors.hpp
+++ b/redfish-core/lib/sensors.hpp
@@ -761,11 +761,11 @@
 
     // Check if sensor has critical threshold alarm
 
-    for (auto& [interface, values] : interfacesDict)
+    for (const auto& [interface, values] : interfacesDict)
     {
         if (interface == "xyz.openbmc_project.Sensor.Threshold.Critical")
         {
-            for (auto& [valueName, value] : values)
+            for (const auto& [valueName, value] : values)
             {
                 if (valueName == "CriticalAlarmHigh" ||
                     valueName == "CriticalAlarmLow")
@@ -798,11 +798,11 @@
     }
 
     // Check if sensor has warning threshold alarm
-    for (auto& [interface, values] : interfacesDict)
+    for (const auto& [interface, values] : interfacesDict)
     {
         if (interface == "xyz.openbmc_project.Sensor.Threshold.Warning")
         {
-            for (auto& [valueName, value] : values)
+            for (const auto& [valueName, value] : values)
             {
                 if (valueName == "WarningAlarmHigh" ||
                     valueName == "WarningAlarmLow")
@@ -866,11 +866,11 @@
 {
     // Assume values exist as is (10^0 == 1) if no scale exists
     int64_t scaleMultiplier = 0;
-    for (auto& [interface, values] : interfacesDict)
+    for (const auto& [interface, values] : interfacesDict)
     {
         if (interface == "xyz.openbmc_project.Sensor.Value")
         {
-            for (auto& [valueName, value] : values)
+            for (const auto& [valueName, value] : values)
             {
                 if (valueName == "Scale")
                 {
@@ -1194,13 +1194,15 @@
                                     return;
                                 }
 
-                                auto allowedFailures = std::get_if<uint8_t>(
-                                    &(findFailures->second));
-                                auto collection =
+                                const uint8_t* allowedFailures =
+                                    std::get_if<uint8_t>(
+                                        &(findFailures->second));
+                                const std::vector<std::string>* collection =
                                     std::get_if<std::vector<std::string>>(
                                         &(findCollection->second));
-                                auto status = std::get_if<std::string>(
-                                    &(findStatus->second));
+                                const std::string* status =
+                                    std::get_if<std::string>(
+                                        &(findStatus->second));
 
                                 if (allowedFailures == nullptr ||
                                     collection == nullptr || status == nullptr)
@@ -1467,11 +1469,11 @@
 {
     // Get properties from Inventory.Item interface
 
-    for (auto& [interface, values] : interfacesDict)
+    for (const auto& [interface, values] : interfacesDict)
     {
         if (interface == "xyz.openbmc_project.Inventory.Item")
         {
-            for (auto& [name, dbusValue] : values)
+            for (const auto& [name, dbusValue] : values)
             {
                 if (name == "Present")
                 {
@@ -1493,7 +1495,7 @@
         // Get properties from Inventory.Decorator.Asset interface
         if (interface == "xyz.openbmc_project.Inventory.Decorator.Asset")
         {
-            for (auto& [name, dbusValue] : values)
+            for (const auto& [name, dbusValue] : values)
             {
                 if (name == "Manufacturer")
                 {
@@ -1537,7 +1539,7 @@
         if (interface ==
             "xyz.openbmc_project.State.Decorator.OperationalStatus")
         {
-            for (auto& [name, dbusValue] : values)
+            for (const auto& [name, dbusValue] : values)
             {
                 if (name == "Functional")
                 {
diff --git a/redfish-core/lib/update_service.hpp b/redfish-core/lib/update_service.hpp
index 3137ab3..ba92748 100644
--- a/redfish-core/lib/update_service.hpp
+++ b/redfish-core/lib/update_service.hpp
@@ -723,7 +723,7 @@
                         nlohmann::json::array();
                     asyncResp->res.jsonValue["Members@odata.count"] = 0;
 
-                    for (auto& obj : subtree)
+                    for (const auto& obj : subtree)
                     {
                         sdbusplus::message::object_path path(obj.first);
                         std::string swId = path.filename();