Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit af863eb

Browse filesBrowse files
committed
Update coding standard for MockStream
1 parent fff5c1a commit af863eb
Copy full SHA for af863eb

File tree

3 files changed

+55
-47
lines changed
Filter options

3 files changed

+55
-47
lines changed

‎src/Symfony/Component/Filesystem/Filesystem.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Filesystem/Filesystem.php
+6-3Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Filesystem;
1313

14+
use RuntimeException;
1415
use Symfony\Component\Filesystem\Exception\IOException;
1516
use Symfony\Component\Filesystem\Exception\FileNotFoundException;
1617

@@ -466,11 +467,13 @@ public function tempnam($dir, $prefix)
466467
$tmpFile = tempnam($hierarchy, $prefix);
467468

468469
// If tempnam failed or no scheme return the filename otherwise prepend the scheme
469-
return false === $tmpFile || null === $scheme ? $tmpFile : $scheme.'://'.$tmpFile;
470+
if (false === $tmpFile || null === $scheme) {
471+
throw new RuntimeException('A temporary file could not be created');
472+
}
470473
}
471474

472475
// Loop until we create a valid temp file or have reached $limit attempts
473-
for ($i = 0; $i < $limit; $i++) {
476+
for ($i = 0; $i < $limit; ++$i) {
474477

475478
// Create a unique filename
476479
$tmpFile = $dir.'/'.$prefix.uniqid(mt_rand(), true);
@@ -555,7 +558,7 @@ private function getSchemeAndHierarchy($filename)
555558
{
556559
$components = explode('://', $filename, 2);
557560

558-
return count($components) >= 2 ? array($components[0], $components[1]) : array(null, $components[0]);
561+
return count($components) === 2 ? array($components[0], $components[1]) : array(null, $components[0]);
559562
}
560563

561564
}

‎src/Symfony/Component/Filesystem/README.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Filesystem/README.md
-3Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,12 @@ $filesystem->rename($origin, $target);
3030

3131
$filesystem->symlink($originDir, $targetDir, $copyOnWindows = false);
3232

33-
$filesystem->tempnam($dir, $prefix);
34-
3533
$filesystem->makePathRelative($endPath, $startPath);
3634

3735
$filesystem->mirror($originDir, $targetDir, \Traversable $iterator = null, $options = array());
3836

3937
$filesystem->isAbsolutePath($file);
4038

41-
$filesystem->dumpFile($file, $content);
4239
```
4340

4441
Resources

‎src/Symfony/Component/Filesystem/Tests/Fixtures/MockStream/MockStream.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Filesystem/Tests/Fixtures/MockStream/MockStream.php
+49-41Lines changed: 49 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,23 @@
11
<?php
22

3-
/**
3+
/*
44
* This file is part of the Symfony package.
5-
* (c) Fabien Potencier <fabien@symfony.com>.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
67
*
78
* For the full copyright and license information, please view the LICENSE
89
* file that was distributed with this source code.
9-
*
10-
* This class is based on VariableStream from the PHP Manual, which is licenced
11-
* under Creative Commons Attribution 3.0 Licence copyright (c) the PHP
12-
* Documentation Group
13-
*
14-
* @url http://php.net/manual/en/stream.streamwrapper.example-1.php
15-
* @url http://php.net/license/
16-
* @url http://creativecommons.org/licenses/by/3.0/legalcode
1710
*/
11+
1812
namespace MockStream;
1913

2014
/**
2115
* Mock stream class to be used with stream_wrapper_register.
22-
*
23-
* stream_wrapper_register('mock', 'MockStream\MockStream')
16+
* stream_wrapper_register('mock', 'MockStream\MockStream').
2417
*/
25-
class MockStream {
26-
private $str_overloaded;
18+
class MockStream
19+
{
20+
private $strOverloaded;
2721
private $content;
2822
private $position;
2923
private $atime;
@@ -37,13 +31,16 @@ class MockStream {
3731
* @param string $path Specifies the URL that was passed to the original function
3832
* @param string $mode The mode used to open the file, as detailed for fopen()
3933
* @param int $options Holds additional flags set by the streams API
40-
* @param string $opened_path If the path is opened successfully, and STREAM_USE_PATH is set in options, opened_path should be set to the full path of the file/resource that was actually opened
34+
* @param string $opened_path If the path is opened successfully, and STREAM_USE_PATH is set in options,
35+
* opened_path should be set to the full path of the file/resource that was actually
36+
* opened
4137
*
4238
* @return bool
4339
*/
44-
public function stream_open($path, $mode, $options, &$opened_path) {
40+
public function stream_open($path, $mode, $options, &$opened_path)
41+
{
4542
// Is mbstring.func_overload applied to string functions (bit 2 set)
46-
$this->str_overloaded = (bool) (ini_get('mbstring.func_overload') & (1 << 2));
43+
$this->strOverloaded = (bool) (ini_get('mbstring.func_overload') & (1 << 2));
4744
$this->path = $path;
4845
$this->content = '';
4946
$this->position = 0;
@@ -60,8 +57,9 @@ public function stream_open($path, $mode, $options, &$opened_path) {
6057
*
6158
* @return string The data
6259
*/
63-
public function stream_read($count) {
64-
$ret = $this->substr($this->varname, $this->position, $count);
60+
public function stream_read($count)
61+
{
62+
$ret = $this->substr($this->content, $this->position, $count);
6563
$this->position += $this->strlen($ret);
6664
$this->atime = time();
6765

@@ -75,7 +73,8 @@ public function stream_read($count) {
7573
*
7674
* @return int Number of bytes that were successfully stored, or 0 if none could be stored
7775
*/
78-
public function stream_write($data) {
76+
public function stream_write($data)
77+
{
7978
$left = $this->substr($this->content, 0, $this->position);
8079
$right = $this->substr($this->content, $this->position + $this->strlen($data));
8180
$this->content = $left.$data.$right;
@@ -91,50 +90,54 @@ public function stream_write($data) {
9190
*
9291
* @return int The current position of the stream
9392
*/
94-
public function stream_tell() {
93+
public function stream_tell()
94+
{
9595
return $this->position;
9696
}
9797

9898
/**
9999
* Tests for end-of-file on a file pointer.
100100
*
101-
* @return bool Return true if the read/write position is at the end of the stream and if no more data is available to be read, or false otherwise
101+
* @return bool Return true if the read/write position is at the end of the stream and if no more data is available
102+
* to be read, or false otherwise
102103
*/
103-
public function stream_eof() {
104+
public function stream_eof()
105+
{
104106
return $this->position >= $this->strlen($this->content);
105107
}
106108

107109
/**
108110
* Seeks to specific location in a stream.
109111
*
110-
* @param string $offset The stream offset to seek to
111-
* @param int $whence Set position based on value
112+
* @param int $offset The stream offset to seek to
113+
* @param int $whence Set position based on value
112114
*
113115
* @return bool Return true if the position was updated, false otherwise
114116
*/
115-
public function stream_seek($offset, $whence) {
117+
public function stream_seek($offset, $whence)
118+
{
116119
switch ($whence) {
117120
case SEEK_SET:
118121
if ($offset < $this->strlen($this->content) && 0 <= $offset) {
119-
$this->position = $offset;
122+
$this->position = $offset;
120123

121-
return true;
124+
return true;
122125
}
123126
break;
124127

125128
case SEEK_CUR:
126129
if (0 <= $offset) {
127-
$this->position += $offset;
130+
$this->position += $offset;
128131

129-
return true;
132+
return true;
130133
}
131134
break;
132135

133136
case SEEK_END:
134137
if (0 <= $this->strlen($this->content) + $offset) {
135-
$this->position = $this->strlen($this->content) + $offset;
138+
$this->position = $this->strlen($this->content) + $offset;
136139

137-
return true;
140+
return true;
138141
}
139142
break;
140143
}
@@ -151,7 +154,8 @@ public function stream_seek($offset, $whence) {
151154
*
152155
* @return bool Return true on success or fale on failure or if option is not implemented
153156
*/
154-
public function stream_metadata($path, $option, $value) {
157+
public function stream_metadata($path, $option, $value)
158+
{
155159
if (STREAM_META_TOUCH === $option) {
156160
$now = array_key_exists(0, $value) ? $value[0] : time();
157161
$this->atime = array_key_exists(1, $value) ? $value[1] : $now;
@@ -169,7 +173,8 @@ public function stream_metadata($path, $option, $value) {
169173
*
170174
* @return array Stream stats
171175
*/
172-
public function stream_stat() {
176+
public function stream_stat()
177+
{
173178
return array(
174179
'dev' => 0,
175180
'ino' => 0,
@@ -195,7 +200,8 @@ public function stream_stat() {
195200
*
196201
* @return array File stats
197202
*/
198-
public function url_stat($path, $flags) {
203+
public function url_stat($path, $flags)
204+
{
199205
return $this->stream_stat();
200206
}
201207

@@ -206,21 +212,23 @@ public function url_stat($path, $flags) {
206212
*
207213
* @return int The number of bytes in the string on success, and 0 if the string is empty
208214
*/
209-
protected function strlen($string) {
210-
return function_exists('mb_strlen') && $this->str_overloaded ? mb_strlen($string, '8bit') : strlen($string);
215+
protected function strlen($string)
216+
{
217+
return function_exists('mb_strlen') && $this->strOverloaded ? mb_strlen($string, '8bit') : strlen($string);
211218
}
212219

213220
/**
214221
* Returns the portion of string specified by the start and length parameters even when substr is overloaded to mb_substr.
215222
*
216223
* @param string $string The input string which must be one character or longer
217-
* @param start $int Starting position in bytes
218-
* @param length $int Length in bytes which if omitted or NULL is passed, extracts all bytes to the end of the string
224+
* @param int $start Starting position in bytes
225+
* @param int $length Length in bytes which if omitted or NULL is passed, extracts all bytes to the end of the string
219226
*
220227
* @return string
221228
*/
222-
protected function substr($string, $start, $length = null) {
223-
return function_exists('mb_substr') && $this->str_overloaded ? mb_substr($string, $start, $length, '8bit') : substr($string, $start, $length);
229+
protected function substr($string, $start, $length = null)
230+
{
231+
return function_exists('mb_substr') && $this->strOverloaded ? mb_substr($string, $start, $length, '8bit') : substr($string, $start, $length);
224232
}
225233

226234
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.