Skip to content

Commit

Permalink
FIX: undefined indexes issue
Browse files Browse the repository at this point in the history
  • Loading branch information
tuegeb committed May 17, 2016
1 parent 5a0d0c7 commit cf25c0d
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 51 deletions.
5 changes: 5 additions & 0 deletions FACTFinder/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,9 @@ protected function convertServerQueryToClientUrl($query)

return $this->urlBuilder->generateUrl($parameters);
}

protected function isValidResponse($jsonData)
{
return (!empty($jsonData) && !isset($jsonData['error']));
}
}
29 changes: 17 additions & 12 deletions FACTFinder/Adapter/Compare.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,15 @@ private function createComparableAttributes()
else
{
$jsonData = $this->getResponseContent();
foreach($jsonData['attributes'] as $attributeData)
if (parent::isValidResponse($jsonData))
{
$name = $attributeData['attributeName'];
$attributes[$name] = $attributeData['different'];
foreach($jsonData['attributes'] as $attributeData)
{
$name = $attributeData['attributeName'];
$attributes[$name] = $attributeData['different'];
}
}
}

return $attributes;
}

Expand Down Expand Up @@ -157,15 +159,18 @@ private function createComparedRecords()
{
$position = 1;
$jsonData = $this->getResponseContent();
foreach($jsonData['records'] as $recordData)
if (parent::isValidResponse($jsonData))
{
$records[] = FF::getInstance(
'Data\Record',
(string)$recordData['id'],
$recordData['record'],
100.0,
$position++
);
foreach($jsonData['records'] as $recordData)
{
$records[] = FF::getInstance(
'Data\Record',
(string)$recordData['id'],
$recordData['record'],
100.0,
$position++
);
}
}
}

Expand Down
20 changes: 12 additions & 8 deletions FACTFinder/Adapter/ProductCampaign.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,23 +147,27 @@ private function createCampaigns()
{
// Use only the first product ID
$productIDs = $this->parameters['productNumber'];
if (is_array($productIDs))
if (is_array($productIDs) && !empty($productIDs))
{
$this->parameters['productNumber'] = $productIDs[0];

}
$jsonData = $this->getResponseContent();

// Restore IDs
$this->parameters['productNumber'] = $productIDs;
}

foreach ($jsonData as $campaignData) {
$campaign = $this->createEmptyCampaignObject($campaignData);
if(parent::isValidResponse($jsonData))
{
foreach ($jsonData as $campaignData) {
$campaign = $this->createEmptyCampaignObject($campaignData);

$this->fillCampaignWithFeedback($campaign, $campaignData);
$this->fillCampaignWithPushedProducts($campaign, $campaignData);
$this->fillCampaignWithFeedback($campaign, $campaignData);
$this->fillCampaignWithPushedProducts($campaign, $campaignData);

$campaigns[] = $campaign;
}
$campaigns[] = $campaign;
}
}
}

$campaignIterator = FF::getInstance(
Expand Down
23 changes: 13 additions & 10 deletions FACTFinder/Adapter/Recommendation.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,17 +145,20 @@ private function createRecommendations()
else
{
$recommenderData = $this->getResponseContent();
if (isset($recommenderData['resultRecords']))
if (parent::isValidResponse($recommenderData))
{
$recommenderData = $recommenderData['resultRecords'];
}
$position = 1;
foreach($recommenderData as $recordData)
{
if ($this->idsOnly)
$records[] = $this->createSparseRecord($recordData);
else
$records[] = $this->createRecord($recordData, $position++);
if (isset($recommenderData['resultRecords']))
{
$recommenderData = $recommenderData['resultRecords'];
}
$position = 1;
foreach($recommenderData as $recordData)
{
if ($this->idsOnly)
$records[] = $this->createSparseRecord($recordData);
else
$records[] = $this->createRecord($recordData, $position++);
}
}
}

Expand Down
24 changes: 12 additions & 12 deletions FACTFinder/Adapter/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private function createResult()

$jsonData = $this->getResponseContent();

if (isset($jsonData['searchResult'])) {
if (parent::isValidResponse($jsonData) && isset($jsonData['searchResult'])) {
$searchResultData = $jsonData['searchResult'];
$refKey = $searchResultData['refKey'];

Expand Down Expand Up @@ -192,7 +192,7 @@ private function createSingleWordSearch()
$singleWordSearch = array();

$jsonData = $this->getResponseContent();
if (!empty($jsonData['searchResult']['singleWordResults']))
if (parent::isValidResponse($jsonData) && !empty($jsonData['searchResult']['singleWordResults']))
{
foreach ($jsonData['searchResult']['singleWordResults'] as $swsData)
{
Expand Down Expand Up @@ -233,7 +233,7 @@ public function getStatus()
$status = $searchStatusEnum::NoResult();

$jsonData = $this->getResponseContent();
if (isset($jsonData['searchResult']))
if (parent::isValidResponse($jsonData) && isset($jsonData['searchResult']))
{
switch($jsonData['searchResult']['resultStatus'])
{
Expand All @@ -257,7 +257,7 @@ public function getArticleNumberStatus()
$status = $articleNumberSearchStatusEnum::IsNoArticleNumberSearch();

$jsonData = $this->getResponseContent();
if (isset($jsonData['searchResult']))
if (parent::isValidResponse($jsonData) && isset($jsonData['searchResult']))
{
switch ($jsonData['searchResult']['resultArticleNumberStatus'])
{
Expand All @@ -278,7 +278,7 @@ public function getArticleNumberStatus()
public function isSearchTimedOut()
{
$jsonData = $this->getResponseContent();
if (isset($jsonData['searchResult']))
if (parent::isValidResponse($jsonData) && isset($jsonData['searchResult']))
{
return $jsonData['searchResult']['timedOut'];
}
Expand All @@ -305,7 +305,7 @@ private function createAfterSearchNavigation()

$filterGroups = array();

if (isset($jsonData['searchResult']['groups'])) {
if (parent::isValidResponse($jsonData) && isset($jsonData['searchResult']['groups'])) {
foreach ($jsonData['searchResult']['groups'] as $groupData)
$filterGroups[] = $this->createFilterGroup($groupData);
}
Expand Down Expand Up @@ -503,7 +503,7 @@ public function createResultsPerPageOptions()

$jsonData = $this->getResponseContent();

if (isset($jsonData['searchResult']))
if (parent::isValidResponse($jsonData) && isset($jsonData['searchResult']))
{
$rppData = $jsonData['searchResult']['resultsPerPageList'];
if (!empty($rppData))
Expand Down Expand Up @@ -559,7 +559,7 @@ private function createPaging()

$jsonData = $this->getResponseContent();

if (isset($jsonData['searchResult']))
if (parent::isValidResponse($jsonData) && isset($jsonData['searchResult']))
{
$pagingData = $jsonData['searchResult']['paging'];
if (!empty($pagingData))
Expand Down Expand Up @@ -644,7 +644,7 @@ private function createSorting()

$jsonData = $this->getResponseContent();

if (isset($jsonData['searchResult']))
if (parent::isValidResponse($jsonData) && isset($jsonData['searchResult']))
{
$sortingData = $jsonData['searchResult']['sortsList'];
if (!empty($sortingData))
Expand Down Expand Up @@ -692,7 +692,7 @@ private function createBreadCrumbTrail()

$jsonData = $this->getResponseContent();

if (isset($jsonData['searchResult']))
if (parent::isValidResponse($jsonData) && isset($jsonData['searchResult']))
{
$breadCrumbTrailData = $jsonData['searchResult']['breadCrumbTrailItems'];
if (!empty($breadCrumbTrailData))
Expand Down Expand Up @@ -749,7 +749,7 @@ private function createCampaigns()
$campaigns = array();
$jsonData = $this->getResponseContent();

if (isset($jsonData['searchResult']['campaigns'])) {
if (parent::isValidResponse($jsonData) && isset($jsonData['searchResult']['campaigns'])) {
foreach ($jsonData['searchResult']['campaigns'] as $campaignData) {
$campaign = $this->createEmptyCampaignObject($campaignData);

Expand Down Expand Up @@ -970,7 +970,7 @@ public function getFollowSearchValue()
{
$jsonData = $this->getResponseContent();
//use searchParams of result if available
if($jsonData && $jsonData['searchResult'] && isset($jsonData['searchResult']['searchParams'])) {
if (parent::isValidResponse($jsonData) && $jsonData['searchResult'] && isset($jsonData['searchResult']['searchParams'])) {
$parameters = FF::getInstance(
'Util\Parameters',
$jsonData['searchResult']['searchParams']
Expand Down
20 changes: 13 additions & 7 deletions FACTFinder/Adapter/SimilarRecords.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,12 @@ private function createSimilarAttributes()
else
{
$jsonData = $this->getResponseContent();
foreach($jsonData['attributes'] as $attributeData)
if(parent::isValidResponse($jsonData))
{
$attributes[$attributeData['name']] = $attributeData['value'];
foreach($jsonData['attributes'] as $attributeData)
{
$attributes[$attributeData['name']] = $attributeData['value'];
}
}
}

Expand Down Expand Up @@ -182,12 +185,15 @@ private function createSimilarRecords()
{
$position = 1;
$jsonData = $this->getResponseContent();
foreach($jsonData['records'] as $recordData)
if(parent::isValidResponse($jsonData))
{
if ($this->idsOnly)
$records[] = $this->createSparseRecord($recordData);
else
$records[] = $this->createRecord($recordData, $position++);
foreach($jsonData['records'] as $recordData)
{
if ($this->idsOnly)
$records[] = $this->createSparseRecord($recordData);
else
$records[] = $this->createRecord($recordData, $position++);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion FACTFinder/Adapter/Suggest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private function createSuggestions()

$this->parameters['format'] = 'json';
$suggestData = $this->getResponseContent();
if (!empty($suggestData))
if (parent::isValidResponse($suggestData))
{
if (isset($suggestData['suggestions']))
{
Expand Down
2 changes: 1 addition & 1 deletion FACTFinder/Adapter/TagCloud.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private function createTagCloud($requestQuery = null)
$tagCloud = array();

$tagCloudData = $this->getResponseContent();
if (!empty($tagCloudData))
if (parent::isValidResponse($tagCloudData))
{
foreach ($tagCloudData as $tagQueryData)
{
Expand Down

0 comments on commit cf25c0d

Please sign in to comment.