Completed
Push — master ( c60cf3...36f595 )
by Sebastien
07:49
created

lib/Cerbere/Model/Hacked/HackedFileHasher.php (5 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Cerbere\Model\Hacked;
4
5
/**
6
 * Base class for the different ways that files can be hashed.
7
 *
8
 * Class HackedFileHasher
9
 * @package Cerbere\Model\Hacked
10
 */
11
abstract class HackedFileHasher {
12
  /**
13
   * Returns a hash of the given filename.
14
   *
15
   * Ignores file line endings
16
   */
17
  public function hash($filename) {
18
    if (file_exists($filename)) {
19
      if ($hash = $this->getCache($filename)) {
20
        return $hash;
21
      }
22
      else {
23
        $hash = $this->performHash($filename);
24
        $this->setCache($filename, $hash);
25
26
        return $hash;
27
      }
28
    }
29
30
    return false;
31
  }
32
33
  /**
34
   * @param string $filename
35
   * @param string $hash
36
   */
37
  public function setCache($filename, $hash) {
0 ignored issues
show
The parameter $filename is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $hash is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
38
    //cache_set($this->getCacheKey($filename), $hash, HACKED_CACHE_TABLE, strtotime('+7 days'));
0 ignored issues
show
Unused Code Comprehensibility introduced by
69% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
39
  }
40
41
  /**
42
   * @param string $filename
43
   * @return string|false
44
   */
45
  public function getCache($filename) {
0 ignored issues
show
The parameter $filename is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
46
    $cache = false;//cache_get($this->getCacheKey($filename), HACKED_CACHE_TABLE);
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
47
48
    if (!empty($cache->data)) {
49
      return $cache->data;
50
    }
51
52
    return false;
53
  }
54
55
  /**
56
   * @param string $filename
57
   * @return string
58
   */
59
  public function getCacheKey($filename) {
60
    $key = array(
61
      'filename' => $filename,
62
      'mtime' => filemtime($filename),
63
      'class_name' => get_class($this),
64
    );
65
66
    return sha1(serialize($key));
67
  }
68
69
  /**
70
   * Compute and return the hash of the given file.
71
   *
72
   * @param string $filename
73
   *   A fully-qualified filename to hash.
74
   *
75
   * @return string
76
   *   The computed hash of the given file.
77
   */
78
  abstract public function performHash($filename);
79
80
  /**
81
   * Compute and return the lines of the given file.
82
   *
83
   * @param string $filename
84
   *   A fully-qualified filename to return.
85
   *
86
   * @return array|false
87
   *   The lines of the given filename or FALSE on failure.
88
   */
89
  abstract public function fetchLines($filename);
90
}
91