GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 7b42e1...c93f43 )
by Marius
10:41 queued 04:09
created

FileAccess::getFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @package domain
4
 * @subpackage access
5
 * @author marius orcsik <[email protected]>
6
 * @date 12.08.07
7
 */
8
namespace vsc\domain\access;
9
10
use vsc\infrastructure\Object;
11
use vsc\ExceptionError;
12
13
class FileAccess extends Object {
14
	private $sUri;
15
16
	private $sCachePath;
17
	protected $saveToCache = true;
18
19 1
	public function __construct($sUri) {
20 1
		$this->sUri = $sUri;
21 1
	}
22
23 1
	public function getUri() {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
24 1
		return $this->sUri;
25
	}
26
27 1
	public function getCachePath() {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
28 1
		return $this->sCachePath;
29
	}
30
31 1
	public function setCachePath($sPath) {
32 1
		if (is_dir($sPath)) {
33 1
			$this->sCachePath = $sPath;
34
		} else {
35
			throw new ExceptionAccess('Path [' . $sPath . '] is invalid for cache');
36
		}
37 1
	}
38
39
	/**
40
	 * @param string $sFile
41
	 * @return string
42
	 */
43 1
	public function getLocalPath($sFile) {
44 1
		return $this->sCachePath . DIRECTORY_SEPARATOR . $sFile;
45
	}
46
47 1
	public function getSignature($sUri) {
48 1
		return md5($sUri . date('Ymd'));
49
	}
50
51
	/**
52
	 * @param string $sUri
53
	 * @return bool
54
	 */
55 1
	public function inCache($sUri) {
56 1
		return (is_file($this->getLocalPath($this->getSignature($sUri))));
57
	}
58
59 1
	public function loadFromCache($sUri) {
60 1
		return file_get_contents($this->getLocalPath($this->getSignature($sUri)));
61
	}
62
63
	/**
64
	 * @param string $sUri
65
	 * @param string $sContent
66
	 * @throws ExceptionError
67
	 */
68 1
	public function cacheFile($sUri, $sContent) {
69 1
		$sFileName = $this->getLocalPath($this->getSignature($sUri));
70
		// creating the file
71 1
		if (!touch($sFileName)) {
72
			throw new ExceptionError('Path [' . $sFileName . '] is not accessible.');
73
		}
74
75 1
		if (is_writable($sFileName)) {
76 1
			file_put_contents($sFileName, $sContent);
77
		} else {
78
			throw new ExceptionError('Path [' . $sFileName . '] is not writable.');
79
		}
80 1
	}
81
82 1
	public function isLocalFile() {
83 1
		return is_file($this->sUri);
84
	}
85
86 1
	public static function getFile($sPath) {
87 1
		return file_get_contents($sPath);
88
	}
89
90 2
	public function load() {
91 2
		if ($this->isLocalFile($this->sUri) || !$this->inCache($this->sUri)) {
0 ignored issues
show
Unused Code introduced by
The call to FileAccess::isLocalFile() has too many arguments starting with $this->sUri.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
92
			// @todo: use curl when file_get_contents doesn't work with urls
93 2
			$sContent = $this->getFile($this->sUri);
94
95
			try {
96 2
				if (!$this->isLocalFile($this->sUri) && $this->saveToCache) {
0 ignored issues
show
Unused Code introduced by
The call to FileAccess::isLocalFile() has too many arguments starting with $this->sUri.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
97 2
					$this->cacheFile($this->sUri, $sContent);
98
				}
99
			} catch (ExceptionAccess $e) {
100
				// no cache dir
101
			} catch (ExceptionError $e) {
102
 				//_e ($e->getTraceAsString());
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...
103
			}
104
105 2
			return $sContent;
106
		} else {
107
			return $this->loadFromCache($this->sUri);
108
		}
109
	}
110
}
111