Change variable scopes

cppcheck correctly notes that a lot of our variables can be declared at
more specific scopes, and in every case, it seems to be correct.

Tested: Redfish service validator passes.  Unit test coverage on others.

Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: Ia4414410d0e8f74a3bd40fdc0e0232450d1a6416
diff --git a/redfish-core/lib/power.hpp b/redfish-core/lib/power.hpp
index 47f0c5d..33aefa3 100644
--- a/redfish-core/lib/power.hpp
+++ b/redfish-core/lib/power.hpp
@@ -273,9 +273,6 @@
                     }
                 }
 
-                nlohmann::json& value =
-                    sensorJson["PowerLimit"]["LimitInWatts"];
-
                 // LimitException is Mandatory attribute as per OCP
                 // Baseline Profile – v1.0.0, so currently making it
                 // "NoAction" as default value to make it OCP Compliant.
@@ -285,7 +282,12 @@
                 {
                     // Redfish specification indicates PowerLimit should
                     // be null if the limit is not enabled.
-                    value = powerCap * std::pow(10, scale);
+                    sensorJson["PowerLimit"]["LimitInWatts"] =
+                        powerCap * std::pow(10, scale);
+                }
+                else
+                {
+                    sensorJson["PowerLimit"]["LimitInWatts"] = nullptr;
                 }
             };