title: Apply principle of Stable Abstraction in PHP
body: <p>Advice from phpMetrics is to make use of the "Stable Abstraction Principle" and listed me some classes.</p>
  
  <p>The classes are very simple and implement <a href="https://www.php-fig.org/psr/psr-16/" rel="nofollow noreferrer">PSR SimpleCache</a>.</p>
  
  <p>How do I apply the principle correctly to this class?</p>
  
  <pre><code>use Psr\SimpleCache\CacheInterface;
  use stdClass;
  
  class Filecache implements CacheInterface
  {
      /**
       * @var stdClass
       */
      protected $obj;
  
      /**
       * @var string Path to the cache file
       */
      protected $file;
  
      /**
       * @param string $cacheFile
       */
      public function __construct($cacheFile)
      {
          $this-&gt;file = $cacheFile;
          if (!file_exists($this-&gt;file)) {
              touch($this-&gt;file);
          }
          $this-&gt;obj = json_decode(file_get_contents($this-&gt;file));
      }
  
      /**
       *
       */
      public function __destruct()
      {
          $file = fopen($this-&gt;file, 'w');
          fwrite($file, json_encode($this-&gt;obj));
          fclose($file);
      }
  
      /**
       * @inheritDoc
       */
      public function get($key, $default = null)
      {
          return isset($this-&gt;obj-&gt;{$key}) ? $this-&gt;obj-&gt;{$key} : $default;
      }
  
      /**
       * @inheritDoc
       */
      public function set($key, $value, $ttl = null)
      {
          if (!$this-&gt;obj instanceof stdClass) {
              $this-&gt;obj = new stdClass();
          }
          $this-&gt;obj-&gt;{$key} = $value;
      }
  
      /**
       * @inheritDoc
       */
      public function delete($key)
      {
          unset($this-&gt;obj-&gt;{$key});
      }
  
      /**
       * @inheritDoc
       */
      public function clear()
      {
          $this-&gt;obj = new stdClass();
          return true;
      }
  
      /**
       * @inheritDoc
       */
      public function getMultiple($keys, $default = null)
      {
          // TODO: Implement getMultiple() method.
      }
  
      /**
       * @inheritDoc
       */
      public function setMultiple($values, $ttl = null)
      {
          // TODO: Implement setMultiple() method.
      }
  
      /**
       * @inheritDoc
       */
      public function deleteMultiple($keys)
      {
          // TODO: Implement deleteMultiple() method.
      }
  
      /**
       * @inheritDoc
       */
      public function has($key)
      {
          return isset($this-&gt;obj-&gt;{$key});
      }
  }
  </code></pre>