Code Duplication    Length = 76-76 lines in 2 locations

src/Loaders/CoreConfigDataLoader.php 1 location

@@ 93-168 (lines=76) @@
90
     * @return mixed The configuration value
91
     * @throws \Exception Is thrown, if nor a value can be found or a default value has been passed
92
     */
93
    public function load($path = null, $default = null, $scope = ScopeKeys::SCOPE_DEFAULT, $scopeId = 0)
94
    {
95
96
        // initialize the core config data
97
        $coreConfigData = array(
98
            MemberNames::PATH => $path,
99
            MemberNames::SCOPE => $scope,
100
            MemberNames::SCOPE_ID => $scopeId
101
        );
102
103
        // generate the UID from the passed data
104
        $uniqueIdentifier = $this->coreConfigDataUidGenerator->generate($coreConfigData);
105
106
        // iterate over the core config data and try to find the requested configuration value
107
        if (isset($this->coreConfigData[$uniqueIdentifier])) {
108
            return $this->coreConfigData[$uniqueIdentifier][MemberNames::VALUE];
109
        }
110
111
        // query whether or not we've to query for the configuration value on fallback level 'websites' also
112
        if ($scope === ScopeKeys::SCOPE_STORES) {
113
            // query whether or not the website with the passed ID is available
114
            foreach ($this->storeWebsites as $storeWebsite) {
115
                if ($storeWebsite[MemberNames::WEBSITE_ID] === $scopeId) {
116
                    // replace scope with 'websites' and website ID
117
                    $coreConfigData = array_merge(
118
                        $coreConfigData,
119
                        array(
120
                            MemberNames::SCOPE    => ScopeKeys::SCOPE_WEBSITES,
121
                            MemberNames::SCOPE_ID => $storeWebsite[MemberNames::WEBSITE_ID]
122
                        )
123
                    );
124
125
                    // generate the UID from the passed data, merged with the 'websites' scope and ID
126
                    $uniqueIdentifier = $this->coreConfigDataUidGenerator->generate($coreConfigData);
127
128
                    // query whether or not, the configuration value on 'websites' level
129
                    if (isset($this->coreConfigData[$uniqueIdentifier][MemberNames::VALUE])) {
130
                        return $this->coreConfigData[$uniqueIdentifier][MemberNames::VALUE];
131
                    }
132
                }
133
            }
134
        }
135
136
        // replace scope with 'default' and scope ID '0'
137
        $coreConfigData = array_merge(
138
            $coreConfigData,
139
            array(
140
                MemberNames::SCOPE    => ScopeKeys::SCOPE_DEFAULT,
141
                MemberNames::SCOPE_ID => 0
142
            )
143
        );
144
145
        // generate the UID from the passed data, merged with the 'default' scope and ID 0
146
        $uniqueIdentifier = $this->coreConfigDataUidGenerator->generate($coreConfigData);
147
148
        // query whether or not, the configuration value on 'default' level
149
        if (isset($this->coreConfigData[$uniqueIdentifier][MemberNames::VALUE])) {
150
            return $this->coreConfigData[$uniqueIdentifier][MemberNames::VALUE];
151
        }
152
153
        // if not, return the passed default value
154
        if ($default !== null) {
155
            return $default;
156
        }
157
158
        // throw an exception if no value can be found
159
        // in the Magento configuration
160
        throw new \Exception(
161
            sprintf(
162
                'Can\'t find a value for configuration "%s-%s-%d" in "core_config_data"',
163
                $path,
164
                $scope,
165
                $scopeId
166
            )
167
        );
168
    }
169
}
170

src/Subjects/AbstractSubject.php 1 location

@@ 1260-1335 (lines=76) @@
1257
     * @throws \Exception Is thrown, if nor a value can be found or a default value has been passed
1258
     * @deprecated Since version 17.x, use TechDivision\Import\Loaders\CoreConfigDataLoader::load() method instead
1259
     */
1260
    public function getCoreConfigData($path, $default = null, $scope = ScopeKeys::SCOPE_DEFAULT, $scopeId = 0)
1261
    {
1262
1263
        // initialize the core config data
1264
        $coreConfigData = array(
1265
            MemberNames::PATH => $path,
1266
            MemberNames::SCOPE => $scope,
1267
            MemberNames::SCOPE_ID => $scopeId
1268
        );
1269
1270
        // generate the UID from the passed data
1271
        $uniqueIdentifier = $this->coreConfigDataUidGenerator->generate($coreConfigData);
1272
1273
        // iterate over the core config data and try to find the requested configuration value
1274
        if (isset($this->coreConfigData[$uniqueIdentifier])) {
1275
            return $this->coreConfigData[$uniqueIdentifier][MemberNames::VALUE];
1276
        }
1277
1278
        // query whether or not we've to query for the configuration value on fallback level 'websites' also
1279
        if ($scope === ScopeKeys::SCOPE_STORES) {
1280
            // query whether or not the website with the passed ID is available
1281
            foreach ($this->storeWebsites as $storeWebsite) {
1282
                if ($storeWebsite[MemberNames::WEBSITE_ID] === $scopeId) {
1283
                    // replace scope with 'websites' and website ID
1284
                    $coreConfigData = array_merge(
1285
                        $coreConfigData,
1286
                        array(
1287
                            MemberNames::SCOPE    => ScopeKeys::SCOPE_WEBSITES,
1288
                            MemberNames::SCOPE_ID => $storeWebsite[MemberNames::WEBSITE_ID]
1289
                        )
1290
                    );
1291
1292
                    // generate the UID from the passed data, merged with the 'websites' scope and ID
1293
                    $uniqueIdentifier = $this->coreConfigDataUidGenerator->generate($coreConfigData);
1294
1295
                    // query whether or not, the configuration value on 'websites' level
1296
                    if (isset($this->coreConfigData[$uniqueIdentifier][MemberNames::VALUE])) {
1297
                        return $this->coreConfigData[$uniqueIdentifier][MemberNames::VALUE];
1298
                    }
1299
                }
1300
            }
1301
        }
1302
1303
        // replace scope with 'default' and scope ID '0'
1304
        $coreConfigData = array_merge(
1305
            $coreConfigData,
1306
            array(
1307
                MemberNames::SCOPE    => ScopeKeys::SCOPE_DEFAULT,
1308
                MemberNames::SCOPE_ID => 0
1309
            )
1310
        );
1311
1312
        // generate the UID from the passed data, merged with the 'default' scope and ID 0
1313
        $uniqueIdentifier = $this->coreConfigDataUidGenerator->generate($coreConfigData);
1314
1315
        // query whether or not, the configuration value on 'default' level
1316
        if (isset($this->coreConfigData[$uniqueIdentifier][MemberNames::VALUE])) {
1317
            return $this->coreConfigData[$uniqueIdentifier][MemberNames::VALUE];
1318
        }
1319
1320
        // if not, return the passed default value
1321
        if ($default !== null) {
1322
            return $default;
1323
        }
1324
1325
        // throw an exception if no value can be found
1326
        // in the Magento configuration
1327
        throw new \Exception(
1328
            sprintf(
1329
                'Can\'t find a value for configuration "%s-%s-%d" in "core_config_data"',
1330
                $path,
1331
                $scope,
1332
                $scopeId
1333
            )
1334
        );
1335
    }
1336
1337
    /**
1338
     * Resolve the original column name for the passed one.