Skip to content

Commit

Permalink
[Cache] Remove silenced warning tiggered by PhpArrayAdapter
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Jan 5, 2017
1 parent be882c4 commit a9dfcd8
Showing 1 changed file with 16 additions and 22 deletions.
38 changes: 16 additions & 22 deletions src/Symfony/Component/Cache/Adapter/PhpArrayAdapter.php
Expand Up @@ -163,14 +163,12 @@ public function warmUp(array $values)
*/
public function getItem($key)
{
if (null === $this->values) {
$this->initialize();
}

if (!is_string($key)) {
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', is_object($key) ? get_class($key) : gettype($key)));
}

if (null === $this->values) {
$this->initialize();
}
if (!isset($this->values[$key])) {
return $this->fallbackPool->getItem($key);
}
Expand Down Expand Up @@ -203,15 +201,14 @@ public function getItem($key)
*/
public function getItems(array $keys = array())
{
if (null === $this->values) {
$this->initialize();
}

foreach ($keys as $key) {
if (!is_string($key)) {
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', is_object($key) ? get_class($key) : gettype($key)));
}
}
if (null === $this->values) {
$this->initialize();
}

return $this->generateItems($keys);
}
Expand All @@ -221,13 +218,12 @@ public function getItems(array $keys = array())
*/
public function hasItem($key)
{
if (null === $this->values) {
$this->initialize();
}

if (!is_string($key)) {
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', is_object($key) ? get_class($key) : gettype($key)));
}
if (null === $this->values) {
$this->initialize();
}

return isset($this->values[$key]) || $this->fallbackPool->hasItem($key);
}
Expand All @@ -249,13 +245,12 @@ public function clear()
*/
public function deleteItem($key)
{
if (null === $this->values) {
$this->initialize();
}

if (!is_string($key)) {
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', is_object($key) ? get_class($key) : gettype($key)));
}
if (null === $this->values) {
$this->initialize();
}

return !isset($this->values[$key]) && $this->fallbackPool->deleteItem($key);
}
Expand All @@ -265,10 +260,6 @@ public function deleteItem($key)
*/
public function deleteItems(array $keys)
{
if (null === $this->values) {
$this->initialize();
}

$deleted = true;
$fallbackKeys = array();

Expand All @@ -283,6 +274,9 @@ public function deleteItems(array $keys)
$fallbackKeys[] = $key;
}
}
if (null === $this->values) {
$this->initialize();
}

if ($fallbackKeys) {
$deleted = $this->fallbackPool->deleteItems($fallbackKeys) && $deleted;
Expand Down Expand Up @@ -328,7 +322,7 @@ public function commit()
*/
private function initialize()
{
$this->values = @(include $this->file) ?: array();
$this->values = file_exists($this->file) ? (include $this->file ?: array()) : array();
}

/**
Expand Down

0 comments on commit a9dfcd8

Please sign in to comment.