Skip to content

Commit

Permalink
CS-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
belgattitude committed Oct 8, 2017
1 parent 4e88239 commit 6bd0b85
Show file tree
Hide file tree
Showing 28 changed files with 86 additions and 104 deletions.
2 changes: 1 addition & 1 deletion .php_cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ return PhpCsFixer\Config::create()
'blank_line_before_return' => true,
'cast_spaces' => true,
'class_definition' => ['singleLine' => true],
'concat_space' => ['spacing' => 'one'], // Different from symfony (none)
'concat_space' => ['spacing' => "none"], // Different from symfony (none)
'declare_equal_normalize' => true,
'function_typehint_space' => true,
'hash_to_slash_comment' => true,
Expand Down
2 changes: 1 addition & 1 deletion src/Soluble/Japha/Bridge/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function __construct(array $options, LoggerInterface $logger = null)
$driver_class = self::$registeredDrivers[$driver] ?? null;

if ($driver_class === null) {
throw new Exception\UnsupportedDriverException(__METHOD__ . " Driver '$driver' is not supported");
throw new Exception\UnsupportedDriverException(__METHOD__." Driver '$driver' is not supported");
}

$this->driver = new $driver_class($options, $logger);
Expand Down
12 changes: 6 additions & 6 deletions src/Soluble/Japha/Bridge/Driver/Pjb62/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ public function begin(string $name, array $st): void
default:
$this->protocol->handler->shutdownBrokenConnection(
sprintf(
'Parser error, check the backend for details, $name: %s, ' .
'Parser error, check the backend for details, $name: %s, '.
'$st params: %s',
$name,
json_encode($st)
Expand Down Expand Up @@ -493,8 +493,8 @@ protected function writeArg($arg): void
$this->protocol->writeString($arg);
} elseif (is_object($arg)) {
if (!$arg instanceof JavaType) {
$msg = "Client failed to writeArg(), IllegalArgument 'arg:" . get_class($arg) . "' not a Java object, using NULL instead";
$this->logger->error("[soluble-japha] $msg (" . __METHOD__ . ')');
$msg = "Client failed to writeArg(), IllegalArgument 'arg:".get_class($arg)."' not a Java object, using NULL instead";
$this->logger->error("[soluble-japha] $msg (".__METHOD__.')');
//trigger_error($msg, E_USER_WARNING);
$this->protocol->writeObject(null);
} else {
Expand Down Expand Up @@ -675,7 +675,7 @@ public function apply(ApplyArg $arg): void
$res = call_user_func_array($ob, $res);
if (is_object($res) && (!($res instanceof JavaType))) {
$msg = "Client failed to applyArg(), Object returned from '$name()' is not a Java object";
$this->logger->warning("[soluble-japha] $msg (" . __METHOD__ . ')');
$this->logger->warning("[soluble-japha] $msg (".__METHOD__.')');
trigger_error($msg, E_USER_WARNING);

$this->protocol->invokeBegin(0, 'makeClosure');
Expand All @@ -692,8 +692,8 @@ public function apply(ApplyArg $arg): void
$this->protocol->writeException($e->__java, $trace);
$this->protocol->resultEnd();
} catch (\Throwable $ex) {
$msg = 'Unchecked exception detected in callback (' . $ex->__toString() . ')';
$this->logger->error("[soluble-japha] $msg (" . __METHOD__ . ')');
$msg = 'Unchecked exception detected in callback ('.$ex->__toString().')';
$this->logger->error("[soluble-japha] $msg (".__METHOD__.')');
trigger_error($msg, E_USER_WARNING);
throw new Exception\RuntimeException($msg);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Soluble/Japha/Bridge/Driver/Pjb62/JavaProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ public function __toString(): string
try {
return (string) $this->__client->invokeMethod(0, 'ObjectToString', [$this]);
} catch (Exception\JavaException $ex) {
$msg = 'Exception in Java::__toString(): ' . HelperFunctions::java_truncate((string) $ex);
$this->__client->getLogger()->warning("[soluble-japha] $msg (" . __METHOD__ . ')');
$msg = 'Exception in Java::__toString(): '.HelperFunctions::java_truncate((string) $ex);
$this->__client->getLogger()->warning("[soluble-japha] $msg (".__METHOD__.')');
trigger_error($msg, E_USER_WARNING);

return '';
Expand Down
6 changes: 3 additions & 3 deletions src/Soluble/Japha/Bridge/Driver/Pjb62/Pjb62Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ public function __construct(array $options, LoggerInterface $logger = null)
} catch (Exception\ConnectionException $e) {
$address = $options['servlet_address'];
$msg = "Cannot connect to php-java-bridge server on '$address', server didn't respond.";
$this->logger->critical("[soluble-japha] $msg (" . $e->getMessage() . ')');
$this->logger->critical("[soluble-japha] $msg (".$e->getMessage().')');
throw $e;
} catch (Exception\InvalidArgumentException $e) {
$msg = 'Invalid arguments, cannot initiate connection to java-bridge.';
$this->logger->error("[soluble-japha] $msg (" . $e->getMessage() . ')');
$this->logger->error("[soluble-japha] $msg (".$e->getMessage().')');
throw $e;
}
}
Expand Down Expand Up @@ -376,7 +376,7 @@ public function getClassName(Interfaces\JavaObject $javaObject): string
$matches = [];
preg_match('/^\[class (.+)\:/', $inspect, $matches);
if (!isset($matches[1]) || $matches[1] == '') {
throw new Exception\UnexpectedException(__METHOD__ . ' Cannot determine class name');
throw new Exception\UnexpectedException(__METHOD__.' Cannot determine class name');
}

return $matches[1];
Expand Down
8 changes: 4 additions & 4 deletions src/Soluble/Japha/Bridge/Driver/Pjb62/PjbProxyClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public static function getInstance(?array $options = null, ?LoggerInterface $log
if (self::$instance === null) {
if ($options === null) {
throw new Exception\InvalidUsageException(
'Cannot instanciate PjbProxyClient without "$options" the first time, ' .
'Cannot instanciate PjbProxyClient without "$options" the first time, '.
'or the instance have been unregistered since'
);
}
Expand Down Expand Up @@ -196,7 +196,7 @@ protected function loadClient(): void
$options = $this->options;

if (!isset($options['servlet_address'])) {
throw new Exception\InvalidArgumentException(__METHOD__ . ' Missing required parameter servlet_address');
throw new Exception\InvalidArgumentException(__METHOD__.' Missing required parameter servlet_address');
}

$connection = static::parseServletUrl($options['servlet_address']);
Expand Down Expand Up @@ -322,7 +322,7 @@ public function isInstanceOf(Interfaces\JavaObject $object, $class): bool
// Will eventually throws ClassNotFoundException
$class = $this->getJavaClass($name);
} elseif (!$class instanceof Interfaces\JavaObject) {
throw new Exception\InvalidArgumentException(__METHOD__ . 'Class $class parameter must be of Interfaces\JavaClass, Interfaces\JavaObject or string');
throw new Exception\InvalidArgumentException(__METHOD__.'Class $class parameter must be of Interfaces\JavaClass, Interfaces\JavaObject or string');
}

return self::getClient()->invokeMethod(0, 'instanceOf', [$object, $class]);
Expand Down Expand Up @@ -436,7 +436,7 @@ public static function parseServletUrl(string $servlet_address): array
$url = parse_url($servlet_address);

if ($url === false || !isset($url['host'])) {
throw new Exception\InvalidArgumentException(__METHOD__ . " Cannot parse url '$servlet_address'");
throw new Exception\InvalidArgumentException(__METHOD__." Cannot parse url '$servlet_address'");
}

$scheme = '';
Expand Down
3 changes: 0 additions & 3 deletions src/Soluble/Japha/Bridge/Driver/Pjb62/Protocol.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,6 @@ public function getOverrideHosts(): string
return Pjb62Driver::getJavaBridgeHeader('X_JAVABRIDGE_OVERRIDE_HOSTS_REDIRECT', $_SERVER);
}

/**
* @param SocketHandler $socketHandler
*/
public function setSocketHandler(SocketHandler $socketHandler): void
{
$this->socketHandler = $socketHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected function getExceptionFromResult(Pjb62\Exception\JavaException $result)
$exceptionClass = $this->defaultException;
}

$cls = '\\Soluble\\Japha\\Bridge\\Exception\\' . $exceptionClass;
$cls = '\\Soluble\\Japha\\Bridge\\Exception\\'.$exceptionClass;

// Public message, mask any login/passwords
$message = preg_replace('/user=([^&\ ]+)|password=([^&\ ]+)/', '****', $message);
Expand Down
4 changes: 2 additions & 2 deletions src/Soluble/Japha/Bridge/Driver/Pjb62/SimpleHttpHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public function getWebAppInternal()

return ($this->java_servlet == 'User' &&
array_key_exists('PHP_SELF', $_SERVER) &&
array_key_exists('HTTP_HOST', $_SERVER)) ? $_SERVER['PHP_SELF'] . 'javabridge' : null;
array_key_exists('HTTP_HOST', $_SERVER)) ? $_SERVER['PHP_SELF'].'javabridge' : null;
}

public function getWebApp(): string
Expand Down Expand Up @@ -228,7 +228,7 @@ public function getChannel(string $channelName): SocketChannelP
try {
$streamSocket = new StreamSocket(
$this->ssl === 'ssl' ? StreamSocket::TRANSPORT_SSL : StreamSocket::TRANSPORT_TCP,
$this->host . ':' . $channelName,
$this->host.':'.$channelName,
self::DEFAULT_CONNECT_TIMEOUT,
[],
true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ protected function open()
try {
$streamSocket = new StreamSocket(
$this->ssl === 'ssl' ? StreamSocket::TRANSPORT_SSL : StreamSocket::TRANSPORT_TCP,
$this->host . ':' . $this->port,
$this->host.':'.$this->port,
self::DEFAULT_CONNECT_TIMEOUT
);
$socket = $streamSocket->getSocket();
Expand Down Expand Up @@ -227,7 +227,7 @@ public function write(string $data): ?int
$compat = PjbProxyClient::getInstance()->getCompatibilityOption($this->protocol->client);
$this->headers = null; // reset headers

$request = $this->httpHeadersPayload . "\r\n" . $this->getBodyFor($compat, $data);
$request = $this->httpHeadersPayload."\r\n".$this->getBodyFor($compat, $data);

$count = @fwrite($this->socket, $request);
if ($count === false) {
Expand Down
2 changes: 1 addition & 1 deletion src/Soluble/Japha/Bridge/Driver/Pjb62/SocketHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function dieWithBrokenConnection(string $msg = ''): void
// Log error
$client = $this->protocol->getClient();

$client->getLogger()->critical("[soluble-japha] Broken connection: $msg, check the backend log for details\" (" . __METHOD__ . ')');
$client->getLogger()->critical("[soluble-japha] Broken connection: $msg, check the backend log for details\" (".__METHOD__.')');

PjbProxyClient::unregisterInstance();
throw new BrokenConnectionException("Broken connection: $msg, check the backend log for details");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ public function checkResult(Exception\JavaException $result): void
if (PjbProxyClient::getInstance()->getOption('java_prefer_values') || ($result->__hasDeclaredExceptions === 'T')) {
throw $result;
} else {
$msg = 'Unchecked exception detected: ' . HelperFunctions::java_truncate($result->__toString());
$msg = 'Unchecked exception detected: '.HelperFunctions::java_truncate($result->__toString());
// Log error
$this->client->getLogger()->critical("[soluble-japha] $msg (" . __METHOD__ . ')');
$this->client->getLogger()->critical("[soluble-japha] $msg (".__METHOD__.')');
trigger_error($msg, E_USER_WARNING);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static function java_get_session_lifetime(): int
public static function java_truncate(string $str): string
{
if (strlen($str) > 955) {
return substr($str, 0, 475) . '[...]' . substr($str, -475);
return substr($str, 0, 475).'[...]'.substr($str, -475);
}

return $str;
Expand Down
8 changes: 4 additions & 4 deletions src/Soluble/Japha/Bridge/Http/Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static function getCookiesHeaderLine(array $cookies = null): ?string
$cookieParts[] = self::serializePHPCookies($k, $v);
}

return 'Cookie: ' . implode(';', $cookieParts);
return 'Cookie: '.implode(';', $cookieParts);
}

/**
Expand All @@ -67,7 +67,7 @@ private static function serializePHPCookies(string $cookieName, $cookieValue): s

case 'array':
foreach ($cookieValue as $cookieValueKey => $cookieValueValue) {
$cookieParts[] = self::serializePHPCookies($cookieName . "[$cookieValueKey]", $cookieValueValue);
$cookieParts[] = self::serializePHPCookies($cookieName."[$cookieValueKey]", $cookieValueValue);
}
break;

Expand All @@ -76,14 +76,14 @@ private static function serializePHPCookies(string $cookieName, $cookieValue): s
break;

case 'boolean':
$cookieParts[] = "$urlEncodedCookieName=" . ($cookieValue ? '1' : '0');
$cookieParts[] = "$urlEncodedCookieName=".($cookieValue ? '1' : '0');
break;

// It's a security risk to serialize an object and send it as a cookie
case 'object':
// Intentional fallthrough
default:
$cookieParts[] = "$urlEncodedCookieName=" . self::UNSUPPORTED_TYPE_VALUE;
$cookieParts[] = "$urlEncodedCookieName=".self::UNSUPPORTED_TYPE_VALUE;
break;
}

Expand Down
8 changes: 4 additions & 4 deletions src/Soluble/Japha/Db/DriverManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function createConnection(string $dsn, string $driverClass = 'com.mysql.j
{
if (!is_string($dsn) || trim($dsn) == '') {
$message = 'DSN param must be a valid (on-empty) string';
throw new Exception\InvalidArgumentException(__METHOD__ . ' ' . $message);
throw new Exception\InvalidArgumentException(__METHOD__.' '.$message);
}

$class = $this->ba->javaClass('java.lang.Class');
Expand Down Expand Up @@ -105,11 +105,11 @@ public static function getJdbcDsn(string $driver, string $db, string $host, stri
if (count($options) > 0) {
$tmp = [];
foreach ($options as $key => $value) {
$tmp[] = urlencode($key) . '=' . urlencode($value);
$tmp[] = urlencode($key).'='.urlencode($value);
}
$extras = '&' . implode('&', $tmp);
$extras = '&'.implode('&', $tmp);
}

return "jdbc:$driver://$host/$db?user=$user&password=$password" . $extras;
return "jdbc:$driver://$host/$db?user=$user&password=$password".$extras;
}
}
6 changes: 3 additions & 3 deletions test/SolubleTestFactories.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static function startJavaBridgeServer()
'port' => $port,
'classpaths' => [
//__DIR__ . '/resources/mysql-connector-java-5.1.36-bin.jar',
__DIR__ . '/resources/*.jar'
__DIR__.'/resources/*.jar'
]
];

Expand Down Expand Up @@ -79,7 +79,7 @@ public static function getCachePath()
{
$cache_dir = $_SERVER['PHPUNIT_CACHE_DIR'];
if (!preg_match('/^\//', $cache_dir)) {
$cache_dir = __DIR__ . DIRECTORY_SEPARATOR . $cache_dir;
$cache_dir = __DIR__.DIRECTORY_SEPARATOR.$cache_dir;
}

return $cache_dir;
Expand All @@ -90,7 +90,7 @@ public static function getCachePath()
*/
public static function getScriptPath()
{
return __DIR__ . DIRECTORY_SEPARATOR . 'scripts';
return __DIR__.DIRECTORY_SEPARATOR.'scripts';
}

public static function getDatabaseConfig()
Expand Down
34 changes: 17 additions & 17 deletions test/bench/simple_benchmarks.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @license MIT License https://github.com/belgattitude/soluble-japha/blob/master/LICENSE.md
*/

require_once __DIR__ . '/../../vendor/autoload.php';
require_once __DIR__.'/../../vendor/autoload.php';

use Soluble\Japha\Bridge\Adapter as BridgeAdapter;

Expand All @@ -18,7 +18,7 @@

$start_total_time = $bm->getTimeMs();

echo '<pre>' . PHP_EOL;
echo '<pre>'.PHP_EOL;

// BENCHING CONNECTION
$start_connection_time = $bm->getTimeMs();
Expand All @@ -34,7 +34,7 @@
]);
$init = $ba->java('java.lang.String');
} catch (\Exception $e) {
die('Error connecting: ' . $e->getMessage());
die('Error connecting: '.$e->getMessage());
}
$end_connection_time = $bm->getTimeMs();
$connection_time = $bm->getFormattedTimeMs($start_connection_time, $end_connection_time);
Expand Down Expand Up @@ -118,7 +118,7 @@ function ($iterations) use ($ba, $jString) {
"\$a = `...String->concat('hello')` . ' world'",
function ($iterations) use ($ba, $jString) {
for ($i = 0; $i < $iterations; ++$i) {
$a = $jString->concat('hello') . ' world';
$a = $jString->concat('hello').' world';
}
}
);
Expand Down Expand Up @@ -208,7 +208,7 @@ function ($iterations) {
'Pure PHP: concat \'$string . "hello"\' ',
function ($iterations) use (&$phpString) {
for ($i = 0; $i < $iterations; ++$i) {
$phpString = $phpString . 'Hello World';
$phpString = $phpString.'Hello World';
}
}
);
Expand All @@ -217,8 +217,8 @@ function ($iterations) use (&$phpString) {
$total_time = $bm->getFormattedTimeMs($start_total_time, $end_total_time);

echo PHP_EOL;
echo '- Connection time: ' . $connection_time . PHP_EOL;
echo '- Total time : ' . $total_time . PHP_EOL;
echo '- Connection time: '.$connection_time.PHP_EOL;
echo '- Total time : '.$total_time.PHP_EOL;
echo PHP_EOL;

class Benchmark
Expand All @@ -244,12 +244,12 @@ public function __construct()
public function time($name, callable $fn)
{
if (!$this->tableHeaderPrinted) {
echo '| Benchmark name | ' . implode('|', array_map(function ($iter) {
echo '| Benchmark name | '.implode('|', array_map(function ($iter) {
return " x$iter ";
}, $this->iterations)) . '| Average | Memory |' . PHP_EOL;
echo '|----| ' . implode('|', array_map(function ($iter) {
}, $this->iterations)).'| Average | Memory |'.PHP_EOL;
echo '|----| '.implode('|', array_map(function ($iter) {
return '----:';
}, $this->iterations)) . '|-------:|----:| ' . PHP_EOL;
}, $this->iterations)).'|-------:|----:| '.PHP_EOL;
$this->tableHeaderPrinted = true;
}

Expand All @@ -272,11 +272,11 @@ public function time($name, callable $fn)
$ttime = array_sum($times);
echo number_format($ttime * 1000, 2);
*/
echo "| $name | " . implode('| ', array_map(function ($time) {
return number_format($time * 1000, 2) . 'ms';
}, $times)) . '| ' .
number_format($avg * 1000, 2) . 'ms| ' .
round($memory / 1024, 2) . 'Kb' . '|' . PHP_EOL;
echo "| $name | ".implode('| ', array_map(function ($time) {
return number_format($time * 1000, 2).'ms';
}, $times)).'| '.
number_format($avg * 1000, 2).'ms| '.
round($memory / 1024, 2).'Kb'.'|'.PHP_EOL;
}

/**
Expand All @@ -289,7 +289,7 @@ public function getFormattedTimeMs($start_time, $end_time)
{
$time = $end_time - $start_time;

return number_format($time, 0, '.', '') . ' ms';
return number_format($time, 0, '.', '').' ms';
}

/**
Expand Down
Loading

0 comments on commit 6bd0b85

Please sign in to comment.