Skip to content

Commit ca737dd

Browse files
committed
Applied PSR2 fixes to the source files.
1 parent 700c406 commit ca737dd

File tree

4 files changed

+158
-163
lines changed

4 files changed

+158
-163
lines changed

src/GzStreamGuzzle.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class GzStreamGuzzle implements StreamInterface
2222
public function __construct(StreamInterface $stream, $readOnly = false, $level = 6)
2323
{
2424
$this->stream = $stream;
25-
$this->level = $level;
25+
$this->level = $level;
2626

2727
if (!$stream->isWritable() || $readOnly) {
2828
$this->mode = 'r';
@@ -42,7 +42,7 @@ public function __construct(StreamInterface $stream, $readOnly = false, $level =
4242

4343
public function readOnlyStream()
4444
{
45-
return new self($this->stream, true, $this->level);
45+
return new self($this->stream, true, $this->level);
4646
}
4747

4848
public function read($length)
@@ -130,7 +130,7 @@ protected function writeHeader()
130130

131131
public function write($string)
132132
{
133-
if ($this->footerLen > 0) {
133+
if ($this->footerLen > 0) {
134134
return false;
135135
}
136136

@@ -160,7 +160,7 @@ public function getSize()
160160

161161
public function getWriteSize()
162162
{
163-
return $this->writeSize;
163+
return $this->writeSize;
164164
}
165165

166166
public function close()
@@ -214,22 +214,21 @@ public function writeFooterEarly()
214214
// Not working as I hoped:
215215
public function undoWriteFooter()
216216
{
217-
if ($this->footerLen > 0)
218-
{
219-
// Attempt to remove the footer content already written by moving to the start of the footer position:
220-
$this->seek(($this->headerLen + $this->writeSize) - 1);
217+
if ($this->footerLen > 0) {
218+
// Attempt to remove the footer content already written by moving to the start of the footer position:
219+
$this->seek(($this->headerLen + $this->writeSize) - 1);
221220

222-
// Restore Hash Context:
223-
$this->hashCtx = $this->hashCtxBeforeFooter;
221+
// Restore Hash Context:
222+
$this->hashCtx = $this->hashCtxBeforeFooter;
224223

225-
// Add the filter back in:
226-
$resource = StreamWrapper::getResource($this->stream);
224+
// Add the filter back in:
225+
$resource = StreamWrapper::getResource($this->stream);
227226
$params = array('level' => $this->level);
228227
$this->filter = stream_filter_append($resource, 'zlib.deflate', STREAM_FILTER_WRITE, $params);
229228
$this->stream = new Stream($resource);
230229

231230
// Reset the Footer Length:
232231
$this->footerLen = 0;
233-
}
232+
}
234233
}
235234
}

src/String.php

Lines changed: 97 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -9,103 +9,102 @@
99

1010
class String
1111
{
12-
protected $gzStream = null;
13-
protected $stream = null;
14-
protected $streamObject = null;
15-
protected $compressionLevel = 6;
16-
17-
public function __construct($readOnly = false, $compressionLevel = 6)
18-
{
19-
$this->compressionLevel = $compressionLevel;
20-
$this->stream = fopen('php://memory', 'w');
21-
$this->streamObject = Psr7\stream_for($this->stream);
22-
$this->gzStream = new GzStreamGuzzle($this->streamObject, $readOnly, $this->compressionLevel);
23-
}
24-
25-
public function write($string, $options = 0, $depth = 512)
26-
{
27-
if (!is_string($string))
28-
{
29-
$string = json_encode($string, $options, $depth);
30-
}
31-
32-
return $this->getGzStream()->write($string);
33-
}
34-
35-
public function prepend($string, $compressionLevel = 6)
36-
{
37-
$this->prepareForRead();
38-
$gzStreamReadOnly = $this->getGzStream()->readOnlyStream();
39-
40-
$this->compressionLevel = $compressionLevel;
41-
$this->stream = fopen('php://memory', 'w');
42-
$this->streamObject = Psr7\stream_for($this->stream);
43-
$this->gzStream = new GzStreamGuzzle($this->streamObject, false, $compressionLevel);
44-
45-
$this->getGzStream()->write($string);
46-
47-
while($buffer = $gzStreamReadOnly->read(4096)) {
48-
$this->getGzStream()->write($buffer);
49-
}
50-
}
51-
52-
public function getCompressedSize()
53-
{
54-
return strlen($this->getCompressedContents());
55-
}
56-
57-
public function getDecompressedContents()
58-
{
59-
return gzdecode($this->getCompressedContents());
60-
}
61-
62-
public function writeDecompressedContents($filename, $lock = false)
63-
{
64-
return file_put_contents($filename, $this->getDecompressedContents(), $lock ? LOCK_EX : 0);
65-
}
66-
67-
public function getCompressedContents()
68-
{
69-
$this->prepareForRead();
70-
return stream_get_contents($this->getStream());
71-
}
72-
73-
public function writeCompressedContents($filename, $lock = false)
74-
{
75-
return file_put_contents($filename, $this->getCompressedContents(), $lock ? LOCK_EX : 0);
76-
}
77-
78-
public function getGzStream()
79-
{
80-
return $this->gzStream;
81-
}
82-
83-
public function prepareForRead()
84-
{
85-
$this->getGzStream()->writeFooterEarly();
12+
protected $gzStream = null;
13+
protected $stream = null;
14+
protected $streamObject = null;
15+
protected $compressionLevel = 6;
16+
17+
public function __construct($readOnly = false, $compressionLevel = 6)
18+
{
19+
$this->compressionLevel = $compressionLevel;
20+
$this->stream = fopen('php://memory', 'w');
21+
$this->streamObject = Psr7\stream_for($this->stream);
22+
$this->gzStream = new GzStreamGuzzle($this->streamObject, $readOnly, $this->compressionLevel);
23+
}
24+
25+
public function write($string, $options = 0, $depth = 512)
26+
{
27+
if (!is_string($string)) {
28+
$string = json_encode($string, $options, $depth);
29+
}
30+
31+
return $this->getGzStream()->write($string);
32+
}
33+
34+
public function prepend($string, $compressionLevel = 6)
35+
{
36+
$this->prepareForRead();
37+
$gzStreamReadOnly = $this->getGzStream()->readOnlyStream();
38+
39+
$this->compressionLevel = $compressionLevel;
40+
$this->stream = fopen('php://memory', 'w');
41+
$this->streamObject = Psr7\stream_for($this->stream);
42+
$this->gzStream = new GzStreamGuzzle($this->streamObject, false, $compressionLevel);
43+
44+
$this->getGzStream()->write($string);
45+
46+
while ($buffer = $gzStreamReadOnly->read(4096)) {
47+
$this->getGzStream()->write($buffer);
48+
}
49+
}
50+
51+
public function getCompressedSize()
52+
{
53+
return strlen($this->getCompressedContents());
54+
}
55+
56+
public function getDecompressedContents()
57+
{
58+
return gzdecode($this->getCompressedContents());
59+
}
60+
61+
public function writeDecompressedContents($filename, $lock = false)
62+
{
63+
return file_put_contents($filename, $this->getDecompressedContents(), $lock ? LOCK_EX : 0);
64+
}
65+
66+
public function getCompressedContents()
67+
{
68+
$this->prepareForRead();
69+
return stream_get_contents($this->getStream());
70+
}
71+
72+
public function writeCompressedContents($filename, $lock = false)
73+
{
74+
return file_put_contents($filename, $this->getCompressedContents(), $lock ? LOCK_EX : 0);
75+
}
76+
77+
public function getGzStream()
78+
{
79+
return $this->gzStream;
80+
}
81+
82+
public function prepareForRead()
83+
{
84+
$this->getGzStream()->writeFooterEarly();
8685
$this->rewind();
87-
}
88-
89-
public function rewind()
90-
{
91-
rewind($this->stream);
92-
}
93-
94-
public function getStream()
95-
{
96-
return $this->stream;
97-
}
98-
99-
public function getStreamObject()
100-
{
101-
return $this->streamObject;
102-
}
103-
104-
public function getReadOnlyStream()
105-
{
106-
$this->prepareForRead();
107-
$gzStreamReadOnly = $this->getGzStream()->readOnlyStream();
108-
109-
return $gzStreamReadOnly;
110-
}
86+
}
87+
88+
public function rewind()
89+
{
90+
rewind($this->stream);
91+
}
92+
93+
public function getStream()
94+
{
95+
return $this->stream;
96+
}
97+
98+
public function getStreamObject()
99+
{
100+
return $this->streamObject;
101+
}
102+
103+
public function getReadOnlyStream()
104+
{
105+
$this->prepareForRead();
106+
$gzStreamReadOnly = $this->getGzStream()->readOnlyStream();
107+
108+
return $gzStreamReadOnly;
109+
}
111110
}

src/StringList.php

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,36 @@
33

44
class StringList
55
{
6-
protected $queue = null;
6+
protected $queue = null;
77

8-
public function __construct()
9-
{
10-
$this->queue = new \SplQueue();
11-
$this->queue->setIteratorMode(\SplDoublyLinkedList::IT_MODE_FIFO | \SplDoublyLinkedList::IT_MODE_DELETE);
12-
}
8+
public function __construct()
9+
{
10+
$this->queue = new \SplQueue();
11+
$this->queue->setIteratorMode(\SplDoublyLinkedList::IT_MODE_FIFO | \SplDoublyLinkedList::IT_MODE_DELETE);
12+
}
1313

14-
public function enqueue(String $string)
15-
{
16-
return $this->queue->enqueue($string);
17-
}
14+
public function enqueue(String $string)
15+
{
16+
return $this->queue->enqueue($string);
17+
}
1818

19-
/**
20-
*
21-
*
22-
* @return Orware\Compressed\String
23-
*/
24-
public function dequeue()
25-
{
26-
return $this->queue->dequeue();
27-
}
19+
/**
20+
*
21+
*
22+
* @return Orware\Compressed\String
23+
*/
24+
public function dequeue()
25+
{
26+
return $this->queue->dequeue();
27+
}
2828

29-
public function isEmpty()
30-
{
31-
return $this->queue->isEmpty();
32-
}
29+
public function isEmpty()
30+
{
31+
return $this->queue->isEmpty();
32+
}
3333

34-
public function count()
35-
{
36-
return $this->queue->count();
37-
}
34+
public function count()
35+
{
36+
return $this->queue->count();
37+
}
3838
}

src/StringMerge.php

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,30 @@
33

44
class StringMerge
55
{
6-
public static function merge($subject, $delimiter, StringList $gzippedStrings)
7-
{
8-
if (!is_string($subject))
9-
{
10-
$subject = json_encode($subject);
11-
}
6+
public static function merge($subject, $delimiter, StringList $gzippedStrings)
7+
{
8+
if (!is_string($subject)) {
9+
$subject = json_encode($subject);
10+
}
1211

13-
$subjectParts = explode($delimiter, $subject);
12+
$subjectParts = explode($delimiter, $subject);
1413

15-
// We have the correct number of Gzipped Strings provided:
16-
$merged = new String();
14+
// We have the correct number of Gzipped Strings provided:
15+
$merged = new String();
1716

18-
foreach($subjectParts as $part)
19-
{
20-
$merged->write($part);
21-
if (!$gzippedStrings->isEmpty())
22-
{
23-
$string = $gzippedStrings->dequeue();
17+
foreach ($subjectParts as $part) {
18+
$merged->write($part);
19+
if (!$gzippedStrings->isEmpty()) {
20+
$string = $gzippedStrings->dequeue();
2421

25-
$readStream = $string->getReadOnlyStream();
26-
while($buffer = $readStream->read(4096)) {
27-
$merged->write($buffer);
28-
}
29-
//$merged->write($string->getDecompressedContents());
30-
}
31-
}
22+
$readStream = $string->getReadOnlyStream();
23+
while ($buffer = $readStream->read(4096)) {
24+
$merged->write($buffer);
25+
}
26+
//$merged->write($string->getDecompressedContents());
27+
}
28+
}
3229

33-
return $merged;
34-
}
35-
}
30+
return $merged;
31+
}
32+
}

0 commit comments

Comments
 (0)