Skip to content

Commit

Permalink
CS fixes in accordance with PSR2, except when in conflict with the PE…
Browse files Browse the repository at this point in the history
…AR CS.
  • Loading branch information
boenrobot committed Dec 26, 2012
1 parent 645048f commit 42f964d
Show file tree
Hide file tree
Showing 15 changed files with 175 additions and 104 deletions.
2 changes: 1 addition & 1 deletion extrasetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
= $phpDir . DIRECTORY_SEPARATOR . $pkg . '.php';
}
}
chdir($oldCwd);
chdir($oldCwd);
23 changes: 15 additions & 8 deletions packagexmlsetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,18 @@


$package->files['tests/bootstrap.php'] = array_merge_recursive(
$package->files['tests/bootstrap.php']->getArrayCopy(), $srcDirTask
$package->files['tests/bootstrap.php']->getArrayCopy(),
$srcDirTask
);

$package->files['docs/phpdoc.dist.xml'] = array_merge_recursive(
$package->files['docs/phpdoc.dist.xml']->getArrayCopy(), $srcDirTask
$package->files['docs/phpdoc.dist.xml']->getArrayCopy(),
$srcDirTask
);

$package->files['docs/doxygen.ini'] = array_merge_recursive(
$package->files['docs/doxygen.ini']->getArrayCopy(), $srcDirTask,
$package->files['docs/doxygen.ini']->getArrayCopy(),
$srcDirTask,
array(
'tasks:replace' => array(
array(
Expand All @@ -70,22 +73,25 @@
] = array_merge_recursive(
$compatible->files[
"test/{$package->channel}/{$package->name}/bootstrap.php"
]->getArrayCopy(), $srcDirTask
]->getArrayCopy(),
$srcDirTask
);

$compatible->files[
"doc/{$package->channel}/{$package->name}/phpdoc.dist.xml"
] = array_merge_recursive(
$compatible->files[
"doc/{$package->channel}/{$package->name}/phpdoc.dist.xml"
]->getArrayCopy(), $srcDirTask
]->getArrayCopy(),
$srcDirTask
);

$compatible->files["doc/{$package->channel}/{$package->name}/doxygen.ini"]
= array_merge_recursive(
$compatible->files[
"doc/{$package->channel}/{$package->name}/doxygen.ini"
]->getArrayCopy(), $srcDirTask,
]->getArrayCopy(),
$srcDirTask,
array(
'tasks:replace' => array(
array(
Expand Down Expand Up @@ -113,7 +119,8 @@
$filename = $path->getPathname();

$package->files[$filename] = array_merge_recursive(
$package->files[$filename]->getArrayCopy(), $srcFileTasks
$package->files[$filename]->getArrayCopy(),
$srcFileTasks
);

if ($hasCompatible) {
Expand All @@ -124,4 +131,4 @@
);
}
}
chdir($oldCwd);
chdir($oldCwd);
3 changes: 1 addition & 2 deletions src/PEAR2/Net/Transmitter/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,4 @@
*/
interface Exception
{

}
}
3 changes: 1 addition & 2 deletions src/PEAR2/Net/Transmitter/FilterCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,5 +224,4 @@ public function valid()
{
return array_key_exists($this->position, $this->filters);
}

}
}
3 changes: 1 addition & 2 deletions src/PEAR2/Net/Transmitter/LockException.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,4 @@
*/
class LockException extends \RuntimeException implements Exception
{

}
}
2 changes: 1 addition & 1 deletion src/PEAR2/Net/Transmitter/NetworkStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@ public function shutdown($direction = self::DIRECTION_ALL)
return array_key_exists($direction, $directionMap)
&& stream_socket_shutdown($this->stream, $directionMap[$direction]);
}
}
}
11 changes: 7 additions & 4 deletions src/PEAR2/Net/Transmitter/SocketException.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,12 @@ class SocketException extends \RuntimeException implements Exception
* @param int $error_no The system level error number.
* @param string $error_str The system level error message.
*/
public function __construct($message = '', $code = 0, $previous = null,
$error_no = null, $error_str = null
public function __construct(
$message = '',
$code = 0,
$previous = null,
$error_no = null,
$error_str = null
) {
parent::__construct($message, $code, $previous);
$this->error_no = $error_no;
Expand Down Expand Up @@ -100,6 +104,5 @@ public function __toString()
}
return $result;
}

// @codeCoverageIgnoreEnd
}
}
34 changes: 23 additions & 11 deletions src/PEAR2/Net/Transmitter/Stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ public function __construct($stream)
}
$this->stream = $stream;
$this->persist = (bool) preg_match(
'#\s?persistent\s?#sm', get_resource_type($stream)
'#\s?persistent\s?#sm',
get_resource_type($stream)
);
}

Expand Down Expand Up @@ -250,13 +251,16 @@ public function send($contents, $offset = null, $length = null)
break;
}
$bytesNow = @stream_copy_to_stream(
$contents, $this->stream, $chunkSize
$contents,
$this->stream,
$chunkSize
);
if (0 != $bytesNow) {
$bytes += $bytesNow;
} else {
throw $this->createException(
'Failed while sending stream.', 2
'Failed while sending stream.',
2
);
}
}
Expand All @@ -278,13 +282,15 @@ public function send($contents, $offset = null, $length = null)
while ($bytes < $bytesToSend) {
if ($this->isAcceptingData()) {
$bytesNow = @fwrite(
$this->stream, substr($contents, $bytes, $chunkSize)
$this->stream,
substr($contents, $bytes, $chunkSize)
);
if (0 != $bytesNow) {
$bytes += $bytesNow;
} else {
throw $this->createException(
'Failed while sending string.', 3
'Failed while sending string.',
3
);
}
}
Expand Down Expand Up @@ -320,7 +326,8 @@ public function receive($length, $what = 'data')
}
}
throw $this->createException(
"Failed while receiving {$what}", 4
"Failed while receiving {$what}",
4
);
}
return $result;
Expand All @@ -341,14 +348,19 @@ public function receive($length, $what = 'data')
* @return resource The received content.
*/
public function receiveStream(
$length, FilterCollection $filters = null, $what = 'stream data'
$length,
FilterCollection $filters = null,
$what = 'stream data'
) {
$result = fopen('php://temp', 'r+b');
$appliedFilters = array();
if (null !== $filters) {
foreach ($filters as $filtername => $params) {
$appliedFilters[] = stream_filter_append(
$result, $filtername, STREAM_FILTER_WRITE, $params
$result,
$filtername,
STREAM_FILTER_WRITE,
$params
);
}
}
Expand All @@ -366,7 +378,8 @@ public function receiveStream(
}
}
throw $this->createException(
"Failed while receiving {$what}", 5
"Failed while receiving {$what}",
5
);
}

Expand Down Expand Up @@ -447,5 +460,4 @@ protected function createException($message, $code = 0)
{
return new StreamException($message, $code);
}

}
}
3 changes: 1 addition & 2 deletions src/PEAR2/Net/Transmitter/StreamException.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,4 @@
*/
class StreamException extends \RuntimeException implements Exception
{

}
}
40 changes: 29 additions & 11 deletions src/PEAR2/Net/Transmitter/TcpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,13 @@ class TcpClient extends NetworkStream
* connection.
* @param resource $context A context for the socket.
*/
public function __construct($host, $port, $persist = false,
$timeout = null, $key = '', $context = null
public function __construct(
$host,
$port,
$persist = false,
$timeout = null,
$key = '',
$context = null
) {
if (strpos($host, ':') !== false) {
$host = "[{$host}]";
Expand All @@ -107,8 +112,12 @@ public function __construct($host, $port, $persist = false,
try {
parent::__construct(
@stream_socket_client(
$this->uri, $this->error_no, $this->error_str,
$timeout, $flags, $context
$this->uri,
$this->error_no,
$this->error_str,
$timeout,
$flags,
$context
)
);
} catch (\Exception $e) {
Expand Down Expand Up @@ -138,7 +147,11 @@ public function __construct($host, $port, $persist = false,
protected function createException($message, $code = 0)
{
return new SocketException(
$message, $code, null, $this->error_no, $this->error_str
$message,
$code,
null,
$this->error_no,
$this->error_str
);
}

Expand Down Expand Up @@ -210,7 +223,7 @@ public function lock($direction = self::DIRECTION_ALL, $replace = false)
);
}
}
} catch(LockException $e) {
} catch (LockException $e) {
if ($direction & self::DIRECTION_SEND
&& !($old & self::DIRECTION_SEND)
) {
Expand Down Expand Up @@ -246,7 +259,8 @@ public function send($contents, $offset = null, $length = null)
&& $this->persist
) {
throw $this->createException(
'Unable to obtain sending lock', 10
'Unable to obtain sending lock',
10
);
}
$result = parent::send($contents, $offset, $length);
Expand All @@ -271,7 +285,8 @@ public function receive($length, $what = 'data')
&& $this->persist
) {
throw $this->createException(
'Unable to obtain receiving lock', 9
'Unable to obtain receiving lock',
9
);
}
$result = parent::receive($length, $what);
Expand All @@ -294,17 +309,20 @@ public function receive($length, $what = 'data')
* @return resource The received content.
*/
public function receiveStream(
$length, FilterCollection $filters = null, $what = 'stream data'
$length,
FilterCollection $filters = null,
$what = 'stream data'
) {
if (false === ($previousState = $this->lock(self::DIRECTION_RECEIVE))
&& $this->persist
) {
throw $this->createException(
'Unable to obtain receiving lock', 9
'Unable to obtain receiving lock',
9
);
}
$result = parent::receiveStream($length, $filters, $what);
$this->lock($previousState, true);
return $result;
}
}
}
10 changes: 6 additions & 4 deletions src/PEAR2/Net/Transmitter/TcpServerConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ public function __construct($server, $timeout = null)
$portString = strrchr($peername, ':');
$this->peerPort = (int) substr($portString, 1);
$ipString = substr(
$peername, 0, strlen($peername) - strlen($portString)
$peername,
0,
strlen($peername) - strlen($portString)
);
if (strpos($ipString, '[') === 0
&& strpos(strrev($ipString), ']') === 0
Expand All @@ -79,7 +81,8 @@ public function __construct($server, $timeout = null)
$this->peerIP = $ipString;
} catch (Exception $e) {
throw $this->createException(
'Failed to initialize connection.', 10
'Failed to initialize connection.',
10
);
}
}
Expand Down Expand Up @@ -118,5 +121,4 @@ protected function createException($message, $code = 0)
{
return new SocketException($message, $code);
}

}
}
Loading

0 comments on commit 42f964d

Please sign in to comment.