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
Pull Request — develop (#1930)
by
unknown
12:28
created

HTTP_Request2_Observer_Download   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 34
rs 10
wmc 7
lcom 1
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B update() 0 23 6
1
<?php
2
3
/**
4
 * Download a file to disk instead of buffering it in memory.
5
 * 
6
 * Source: https://pear.php.net/manual/en/package.http.http-request2.observers.php
7
 */
8
class HTTP_Request2_Observer_Download implements SplObserver
9
{
10
	protected $filename;
11
	protected $fp;
12
13
	public function __construct($filename)
14
	{
15
		$this->filename = $filename;
16
	}
17
18
	public function update(SplSubject $subject)
19
	{
20
		$event = $subject->getLastEvent();
21
22
		switch($event['name'])
23
		{
24
			case 'receivedHeaders':
25
				$this->fp = @fopen($this->filename, 'wb');
26
				if(!$this->fp)
27
				{
28
					throw new Exception("Cannot open target file '{$filename}'");
29
				}
30
				break;
31
32
			case 'receivedBodyPart':
33
			case 'receivedEncodedBodyPart':
34
				fwrite($this->fp, $event['data']);
35
				break;
36
37
			case 'receivedBody':
38
				fclose($this->fp);
39
		}
40
	}
41
}
42