Completed
Push — master ( e1606d...8743fe )
by Morris
20:29 queued 07:56
created
apps/dav/lib/Upload/AssemblyStream.php 2 patches
Indentation   +197 added lines, -197 removed lines patch added patch discarded remove patch
@@ -39,227 +39,227 @@
 block discarded – undo
39 39
  */
40 40
 class AssemblyStream implements \Icewind\Streams\File {
41 41
 
42
-	/** @var resource */
43
-	private $context;
42
+    /** @var resource */
43
+    private $context;
44 44
 
45
-	/** @var IFile[] */
46
-	private $nodes;
45
+    /** @var IFile[] */
46
+    private $nodes;
47 47
 
48
-	/** @var int */
49
-	private $pos = 0;
48
+    /** @var int */
49
+    private $pos = 0;
50 50
 
51
-	/** @var int */
52
-	private $size = 0;
51
+    /** @var int */
52
+    private $size = 0;
53 53
 
54
-	/** @var resource */
55
-	private $currentStream = null;
54
+    /** @var resource */
55
+    private $currentStream = null;
56 56
 
57
-	/** @var int */
58
-	private $currentNode = 0;
57
+    /** @var int */
58
+    private $currentNode = 0;
59 59
 
60
-	/** @var int */
61
-	private $currentNodeRead = 0;
60
+    /** @var int */
61
+    private $currentNodeRead = 0;
62 62
 
63
-	/**
64
-	 * @param string $path
65
-	 * @param string $mode
66
-	 * @param int $options
67
-	 * @param string &$opened_path
68
-	 * @return bool
69
-	 */
70
-	public function stream_open($path, $mode, $options, &$opened_path) {
71
-		$this->loadContext('assembly');
63
+    /**
64
+     * @param string $path
65
+     * @param string $mode
66
+     * @param int $options
67
+     * @param string &$opened_path
68
+     * @return bool
69
+     */
70
+    public function stream_open($path, $mode, $options, &$opened_path) {
71
+        $this->loadContext('assembly');
72 72
 
73
-		$nodes = $this->nodes;
74
-		// http://stackoverflow.com/a/10985500
75
-		@usort($nodes, function (IFile $a, IFile $b) {
76
-			return strnatcmp($a->getName(), $b->getName());
77
-		});
78
-		$this->nodes = array_values($nodes);
79
-		if (count($this->nodes) > 0) {
80
-			$this->currentStream = $this->getStream($this->nodes[0]);
81
-		}
82
-		$this->size = array_reduce($this->nodes, function ($size, IFile $file) {
83
-			return $size + $file->getSize();
84
-		}, 0);
85
-		return true;
86
-	}
73
+        $nodes = $this->nodes;
74
+        // http://stackoverflow.com/a/10985500
75
+        @usort($nodes, function (IFile $a, IFile $b) {
76
+            return strnatcmp($a->getName(), $b->getName());
77
+        });
78
+        $this->nodes = array_values($nodes);
79
+        if (count($this->nodes) > 0) {
80
+            $this->currentStream = $this->getStream($this->nodes[0]);
81
+        }
82
+        $this->size = array_reduce($this->nodes, function ($size, IFile $file) {
83
+            return $size + $file->getSize();
84
+        }, 0);
85
+        return true;
86
+    }
87 87
 
88
-	/**
89
-	 * @param string $offset
90
-	 * @param int $whence
91
-	 * @return bool
92
-	 */
93
-	public function stream_seek($offset, $whence = SEEK_SET) {
94
-		return false;
95
-	}
88
+    /**
89
+     * @param string $offset
90
+     * @param int $whence
91
+     * @return bool
92
+     */
93
+    public function stream_seek($offset, $whence = SEEK_SET) {
94
+        return false;
95
+    }
96 96
 
97
-	/**
98
-	 * @return int
99
-	 */
100
-	public function stream_tell() {
101
-		return $this->pos;
102
-	}
97
+    /**
98
+     * @return int
99
+     */
100
+    public function stream_tell() {
101
+        return $this->pos;
102
+    }
103 103
 
104
-	/**
105
-	 * @param int $count
106
-	 * @return string
107
-	 */
108
-	public function stream_read($count) {
109
-		if (is_null($this->currentStream)) {
110
-			return '';
111
-		}
104
+    /**
105
+     * @param int $count
106
+     * @return string
107
+     */
108
+    public function stream_read($count) {
109
+        if (is_null($this->currentStream)) {
110
+            return '';
111
+        }
112 112
 
113
-		do {
114
-			$data = fread($this->currentStream, $count);
115
-			$read = strlen($data);
116
-			$this->currentNodeRead += $read;
113
+        do {
114
+            $data = fread($this->currentStream, $count);
115
+            $read = strlen($data);
116
+            $this->currentNodeRead += $read;
117 117
 
118
-			if (feof($this->currentStream)) {
119
-				fclose($this->currentStream);
120
-				$currentNodeSize = $this->nodes[$this->currentNode]->getSize();
121
-				if ($this->currentNodeRead < $currentNodeSize) {
122
-					throw new \Exception('Stream from assembly node shorter than expected, got ' . $this->currentNodeRead . ' bytes, expected ' . $currentNodeSize);
123
-				}
124
-				$this->currentNode++;
125
-				$this->currentNodeRead = 0;
126
-				if ($this->currentNode < count($this->nodes)) {
127
-					$this->currentStream = $this->getStream($this->nodes[$this->currentNode]);
128
-				} else {
129
-					$this->currentStream = null;
130
-				}
131
-			}
132
-			// if no data read, try again with the next node because
133
-			// returning empty data can make the caller think there is no more
134
-			// data left to read
135
-		} while ($read === 0 && !is_null($this->currentStream));
118
+            if (feof($this->currentStream)) {
119
+                fclose($this->currentStream);
120
+                $currentNodeSize = $this->nodes[$this->currentNode]->getSize();
121
+                if ($this->currentNodeRead < $currentNodeSize) {
122
+                    throw new \Exception('Stream from assembly node shorter than expected, got ' . $this->currentNodeRead . ' bytes, expected ' . $currentNodeSize);
123
+                }
124
+                $this->currentNode++;
125
+                $this->currentNodeRead = 0;
126
+                if ($this->currentNode < count($this->nodes)) {
127
+                    $this->currentStream = $this->getStream($this->nodes[$this->currentNode]);
128
+                } else {
129
+                    $this->currentStream = null;
130
+                }
131
+            }
132
+            // if no data read, try again with the next node because
133
+            // returning empty data can make the caller think there is no more
134
+            // data left to read
135
+        } while ($read === 0 && !is_null($this->currentStream));
136 136
 
137
-		// update position
138
-		$this->pos += $read;
139
-		return $data;
140
-	}
137
+        // update position
138
+        $this->pos += $read;
139
+        return $data;
140
+    }
141 141
 
142
-	/**
143
-	 * @param string $data
144
-	 * @return int
145
-	 */
146
-	public function stream_write($data) {
147
-		return false;
148
-	}
142
+    /**
143
+     * @param string $data
144
+     * @return int
145
+     */
146
+    public function stream_write($data) {
147
+        return false;
148
+    }
149 149
 
150
-	/**
151
-	 * @param int $option
152
-	 * @param int $arg1
153
-	 * @param int $arg2
154
-	 * @return bool
155
-	 */
156
-	public function stream_set_option($option, $arg1, $arg2) {
157
-		return false;
158
-	}
150
+    /**
151
+     * @param int $option
152
+     * @param int $arg1
153
+     * @param int $arg2
154
+     * @return bool
155
+     */
156
+    public function stream_set_option($option, $arg1, $arg2) {
157
+        return false;
158
+    }
159 159
 
160
-	/**
161
-	 * @param int $size
162
-	 * @return bool
163
-	 */
164
-	public function stream_truncate($size) {
165
-		return false;
166
-	}
160
+    /**
161
+     * @param int $size
162
+     * @return bool
163
+     */
164
+    public function stream_truncate($size) {
165
+        return false;
166
+    }
167 167
 
168
-	/**
169
-	 * @return array
170
-	 */
171
-	public function stream_stat() {
172
-		return [];
173
-	}
168
+    /**
169
+     * @return array
170
+     */
171
+    public function stream_stat() {
172
+        return [];
173
+    }
174 174
 
175
-	/**
176
-	 * @param int $operation
177
-	 * @return bool
178
-	 */
179
-	public function stream_lock($operation) {
180
-		return false;
181
-	}
175
+    /**
176
+     * @param int $operation
177
+     * @return bool
178
+     */
179
+    public function stream_lock($operation) {
180
+        return false;
181
+    }
182 182
 
183
-	/**
184
-	 * @return bool
185
-	 */
186
-	public function stream_flush() {
187
-		return false;
188
-	}
183
+    /**
184
+     * @return bool
185
+     */
186
+    public function stream_flush() {
187
+        return false;
188
+    }
189 189
 
190
-	/**
191
-	 * @return bool
192
-	 */
193
-	public function stream_eof() {
194
-		return $this->pos >= $this->size || $this->currentStream === null;
195
-	}
190
+    /**
191
+     * @return bool
192
+     */
193
+    public function stream_eof() {
194
+        return $this->pos >= $this->size || $this->currentStream === null;
195
+    }
196 196
 
197
-	/**
198
-	 * @return bool
199
-	 */
200
-	public function stream_close() {
201
-		return true;
202
-	}
197
+    /**
198
+     * @return bool
199
+     */
200
+    public function stream_close() {
201
+        return true;
202
+    }
203 203
 
204 204
 
205
-	/**
206
-	 * Load the source from the stream context and return the context options
207
-	 *
208
-	 * @param string $name
209
-	 * @return array
210
-	 * @throws \Exception
211
-	 */
212
-	protected function loadContext($name) {
213
-		$context = stream_context_get_options($this->context);
214
-		if (isset($context[$name])) {
215
-			$context = $context[$name];
216
-		} else {
217
-			throw new \BadMethodCallException('Invalid context, "' . $name . '" options not set');
218
-		}
219
-		if (isset($context['nodes']) and is_array($context['nodes'])) {
220
-			$this->nodes = $context['nodes'];
221
-		} else {
222
-			throw new \BadMethodCallException('Invalid context, nodes not set');
223
-		}
224
-		return $context;
225
-	}
205
+    /**
206
+     * Load the source from the stream context and return the context options
207
+     *
208
+     * @param string $name
209
+     * @return array
210
+     * @throws \Exception
211
+     */
212
+    protected function loadContext($name) {
213
+        $context = stream_context_get_options($this->context);
214
+        if (isset($context[$name])) {
215
+            $context = $context[$name];
216
+        } else {
217
+            throw new \BadMethodCallException('Invalid context, "' . $name . '" options not set');
218
+        }
219
+        if (isset($context['nodes']) and is_array($context['nodes'])) {
220
+            $this->nodes = $context['nodes'];
221
+        } else {
222
+            throw new \BadMethodCallException('Invalid context, nodes not set');
223
+        }
224
+        return $context;
225
+    }
226 226
 
227
-	/**
228
-	 * @param IFile[] $nodes
229
-	 * @return resource
230
-	 *
231
-	 * @throws \BadMethodCallException
232
-	 */
233
-	public static function wrap(array $nodes) {
234
-		$context = stream_context_create([
235
-			'assembly' => [
236
-				'nodes' => $nodes
237
-			]
238
-		]);
239
-		stream_wrapper_register('assembly', self::class);
240
-		try {
241
-			$wrapped = fopen('assembly://', 'r', null, $context);
242
-		} catch (\BadMethodCallException $e) {
243
-			stream_wrapper_unregister('assembly');
244
-			throw $e;
245
-		}
246
-		stream_wrapper_unregister('assembly');
247
-		return $wrapped;
248
-	}
227
+    /**
228
+     * @param IFile[] $nodes
229
+     * @return resource
230
+     *
231
+     * @throws \BadMethodCallException
232
+     */
233
+    public static function wrap(array $nodes) {
234
+        $context = stream_context_create([
235
+            'assembly' => [
236
+                'nodes' => $nodes
237
+            ]
238
+        ]);
239
+        stream_wrapper_register('assembly', self::class);
240
+        try {
241
+            $wrapped = fopen('assembly://', 'r', null, $context);
242
+        } catch (\BadMethodCallException $e) {
243
+            stream_wrapper_unregister('assembly');
244
+            throw $e;
245
+        }
246
+        stream_wrapper_unregister('assembly');
247
+        return $wrapped;
248
+    }
249 249
 
250
-	/**
251
-	 * @param IFile $node
252
-	 * @return resource
253
-	 */
254
-	private function getStream(IFile $node) {
255
-		$data = $node->get();
256
-		if (is_resource($data)) {
257
-			return $data;
258
-		} else {
259
-			$tmp = fopen('php://temp', 'w+');
260
-			fwrite($tmp, $data);
261
-			rewind($tmp);
262
-			return $tmp;
263
-		}
264
-	}
250
+    /**
251
+     * @param IFile $node
252
+     * @return resource
253
+     */
254
+    private function getStream(IFile $node) {
255
+        $data = $node->get();
256
+        if (is_resource($data)) {
257
+            return $data;
258
+        } else {
259
+            $tmp = fopen('php://temp', 'w+');
260
+            fwrite($tmp, $data);
261
+            rewind($tmp);
262
+            return $tmp;
263
+        }
264
+    }
265 265
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -72,14 +72,14 @@  discard block
 block discarded – undo
72 72
 
73 73
 		$nodes = $this->nodes;
74 74
 		// http://stackoverflow.com/a/10985500
75
-		@usort($nodes, function (IFile $a, IFile $b) {
75
+		@usort($nodes, function(IFile $a, IFile $b) {
76 76
 			return strnatcmp($a->getName(), $b->getName());
77 77
 		});
78 78
 		$this->nodes = array_values($nodes);
79 79
 		if (count($this->nodes) > 0) {
80 80
 			$this->currentStream = $this->getStream($this->nodes[0]);
81 81
 		}
82
-		$this->size = array_reduce($this->nodes, function ($size, IFile $file) {
82
+		$this->size = array_reduce($this->nodes, function($size, IFile $file) {
83 83
 			return $size + $file->getSize();
84 84
 		}, 0);
85 85
 		return true;
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 				fclose($this->currentStream);
120 120
 				$currentNodeSize = $this->nodes[$this->currentNode]->getSize();
121 121
 				if ($this->currentNodeRead < $currentNodeSize) {
122
-					throw new \Exception('Stream from assembly node shorter than expected, got ' . $this->currentNodeRead . ' bytes, expected ' . $currentNodeSize);
122
+					throw new \Exception('Stream from assembly node shorter than expected, got '.$this->currentNodeRead.' bytes, expected '.$currentNodeSize);
123 123
 				}
124 124
 				$this->currentNode++;
125 125
 				$this->currentNodeRead = 0;
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
 		if (isset($context[$name])) {
215 215
 			$context = $context[$name];
216 216
 		} else {
217
-			throw new \BadMethodCallException('Invalid context, "' . $name . '" options not set');
217
+			throw new \BadMethodCallException('Invalid context, "'.$name.'" options not set');
218 218
 		}
219 219
 		if (isset($context['nodes']) and is_array($context['nodes'])) {
220 220
 			$this->nodes = $context['nodes'];
Please login to merge, or discard this patch.