Skip to content

Commit

Permalink
Merge pull request #11 from ingenerator/namespace-global-functions
Browse files Browse the repository at this point in the history
Run php-cs-fixer native_function_invocation fix
  • Loading branch information
craig410 authored Apr 2, 2019
2 parents f900314 + 86251ef commit 5c6ddbf
Show file tree
Hide file tree
Showing 18 changed files with 90 additions and 88 deletions.
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
sudo: false
language: php
php:
- '5.5'
- '5.6'
- '7.1'
- '7.2'

# Only build main branches : feature branches will be covered by the PR builder
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
### Unreleased

### v0.2.0 (2019-04-02)

* Drop support for php < 7.2
* Run test suite against php 7.2

### v0.1.6 (2019-03-18)

* Update StoppedMockClock to support newer phpunit (use namespaced assert class) and add
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
}
],
"require": {
"php": "^5.5||^7.0"
"php": "^7.2"
},
"require-dev": {
"phpunit/phpunit": "^4.8||^6.5",
"johnkary/phpunit-speedtrap": "^1.0||^2.0"
"phpunit/phpunit": "^6.5",
"johnkary/phpunit-speedtrap": "^2.0"
},
"support": {
"source": "https://github.com/ingenerator/php-utils",
Expand Down
20 changes: 10 additions & 10 deletions src/CSV/CSVWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@ class CSVWriter
*/
public function open($file, array $options = [])
{
if (is_resource($file) AND (get_resource_type($file) === 'stream')) {
if (\is_resource($file) AND (\get_resource_type($file) === 'stream')) {
$this->resource = $file;
$this->owns_resource = FALSE;
} elseif (is_string($file)) {
$this->resource = fopen($file, 'w');
} elseif (\is_string($file)) {
$this->resource = \fopen($file, 'w');
$this->owns_resource = TRUE;
} else {
throw new \InvalidArgumentException(
'Expected `file` to be string or an existing resource'
);
}
$this->expect_schema = NULL;
$this->options = array_merge($this->options, $options);
$this->options = \array_merge($this->options, $options);
}

/**
Expand All @@ -65,24 +65,24 @@ public function write(array $row)
throw new \LogicException('Cannot write to a closed file');
}

$row_schema = array_keys($row);
$row_schema = \array_keys($row);

if ($this->expect_schema === NULL) {
if ($this->options['write_utf8_bom']) {
fputs($this->resource, static::UTF8_BOM);
\fputs($this->resource, static::UTF8_BOM);
}
$this->expect_schema = $row_schema;
fputcsv($this->resource, $this->expect_schema);
\fputcsv($this->resource, $this->expect_schema);
} elseif ($this->expect_schema !== $row_schema) {
throw MismatchedSchemaException::forSchema($this->expect_schema, $row_schema);
}

fputcsv($this->resource, $row);
\fputcsv($this->resource, $row);
}

protected function isResourceOpen()
{
return $this->resource && (get_resource_type($this->resource) === 'stream');
return $this->resource && (\get_resource_type($this->resource) === 'stream');
}

public function close()
Expand All @@ -92,7 +92,7 @@ public function close()
}

if ($this->owns_resource) {
fclose($this->resource);
\fclose($this->resource);
}

$this->resource = NULL;
Expand Down
4 changes: 2 additions & 2 deletions src/CSV/MismatchedSchemaException.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public static function forSchema(array $expected, array $actual)
{
return new static(
'Mismatched row schema in CSV file:'."\n"
.'Expected: '.json_encode($expected)."\n"
.'Actual: '.json_encode($actual)
.'Expected: '.\json_encode($expected)."\n"
.'Actual: '.\json_encode($actual)
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/DateTime/Clock/RealtimeClock.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ public function getDateTime()
*/
public function getMicrotime()
{
return microtime(TRUE);
return \microtime(TRUE);
}

/**
* @param $microseconds
*/
public function usleep($microseconds)
{
usleep($microseconds);
\usleep($microseconds);
}
}
2 changes: 1 addition & 1 deletion src/DateTime/Clock/StoppedMockClock.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static function atTimeAgo($interval_spec)

public function getDateTime()
{
return (new \DateTimeImmutable)->setTimestamp(floor($this->current_microtime));
return (new \DateTimeImmutable)->setTimestamp(\floor($this->current_microtime));
}

public function getMicrotime()
Expand Down
4 changes: 2 additions & 2 deletions src/Object/ConstantDirectory.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ public static function forClass($class)
*/
public function filterConstants($prefix)
{
$prefix_len = strlen($prefix);
$prefix_len = \strlen($prefix);
$consts = [];
foreach ($this->listConstants() as $name => $value) {
if (strncmp($name, $prefix, $prefix_len) === 0) {
if (\strncmp($name, $prefix, $prefix_len) === 0) {
$consts[$name] = $value;
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/Object/ObjectPropertyPopulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public static function assign($object, $property, $value)
*/
public static function assignHash($object, array $properties)
{
if ($undefined = static::listUndefinedProperties($object, array_keys($properties))) {
if ($undefined = static::listUndefinedProperties($object, \array_keys($properties))) {
throw new \InvalidArgumentException(
'Undefined properties on '.get_class($object).' : '.json_encode($undefined)
'Undefined properties on '.\get_class($object).' : '.\json_encode($undefined)
);
}

Expand All @@ -58,11 +58,11 @@ function ($object, array $properties) {

private static function listUndefinedProperties($object, array $property_names)
{
return array_values(
array_filter(
return \array_values(
\array_filter(
$property_names,
function ($property_name) use ($object) {
return ! property_exists($object, $property_name);
return ! \property_exists($object, $property_name);
}
)
);
Expand Down
2 changes: 1 addition & 1 deletion src/Object/ObjectPropertyRipper.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ObjectPropertyRipper
*/
public static function rip($object, array $properties)
{
$ripper = static::getRipper(get_class($object));
$ripper = static::getRipper(\get_class($object));

return $ripper($object, $properties);
}
Expand Down
30 changes: 15 additions & 15 deletions src/Repository/AbstractArrayRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected function __construct(array $entities)
*/
public static function with($entity)
{
return static::withList(func_get_args());
return static::withList(\func_get_args());
}

/**
Expand Down Expand Up @@ -132,11 +132,11 @@ protected function assertSavedOnly($entity)
*/
protected function formatSaveLog($entity)
{
return sprintf(
return \sprintf(
"%s (object %s) with data:\n%s\n",
get_class($entity),
spl_object_hash($entity),
json_encode($this->entityToArray($entity), JSON_PRETTY_PRINT)
\get_class($entity),
\spl_object_hash($entity),
\json_encode($this->entityToArray($entity), JSON_PRETTY_PRINT)
);
}

Expand All @@ -152,7 +152,7 @@ protected function formatSaveLog($entity)
*/
protected function entityToArray($entity, & $seen_objects = [])
{
$entity_hash = spl_object_hash($entity);
$entity_hash = \spl_object_hash($entity);
if (isset($seen_objects[$entity_hash])) {
return '**RECURSION**';
} else {
Expand All @@ -161,17 +161,17 @@ protected function entityToArray($entity, & $seen_objects = [])

$all_props = \Closure::bind(
function ($e) {
return get_object_vars($e);
return \get_object_vars($e);
},
NULL,
$entity
);
$obj_identity = function ($a) {
return get_class($a).'#'.spl_object_hash($a);
return \get_class($a).'#'.\spl_object_hash($a);
};
$result = [];
foreach ($all_props($entity) as $key => $var) {
if ( ! is_object($var)) {
if ( ! \is_object($var)) {
$result[$key] = $var;
} elseif ($var instanceof Collection) {
$result[$key] = [];
Expand All @@ -181,7 +181,7 @@ function ($e) {
];
}
} elseif ($var instanceof \DateTimeInterface) {
$result[$key][get_class($var)] = $var->format(\DateTime::ISO8601);
$result[$key][\get_class($var)] = $var->format(\DateTime::ISO8601);
} else {
$result[$key] = [
$obj_identity($var) => $this->entityToArray($var, $seen_objects)
Expand Down Expand Up @@ -209,7 +209,7 @@ protected function countWith($callable)
{
$counts = [];
foreach ($this->entities as $entity) {
$group = call_user_func($callable, $entity);
$group = \call_user_func($callable, $entity);
$counts[$group] = isset($counts[$group]) ? ++$counts[$group] : 1;
}
return $counts;
Expand Down Expand Up @@ -245,13 +245,13 @@ protected function loadWith($callable)
protected function findWith($callable)
{
$entities = $this->listWith($callable);
if (count($entities) > 1) {
if (\count($entities) > 1) {
throw new \UnexpectedValueException(
'Found multiple entities : expected unique condition.'
);
}

return array_pop($entities);
return \array_pop($entities);
}

/**
Expand All @@ -265,7 +265,7 @@ protected function listWith($callable)
{
$entities = [];
foreach ($this->entities as $entity) {
if (call_user_func($callable, $entity)) {
if (\call_user_func($callable, $entity)) {
$entities[] = $entity;
}
}
Expand All @@ -284,7 +284,7 @@ protected function listWith($callable)
protected function saveEntity($entity)
{
$this->save_log .= $this->formatSaveLog($entity);
if ( ! in_array($entity, $this->entities, TRUE)) {
if ( ! \in_array($entity, $this->entities, TRUE)) {
$this->entities[] = $entity;
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/Session/MysqlSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ public function __construct(PDO $db, $hash_salt, $lock_timeout = 20)
$this->db = $db;
$this->hash_salt = $hash_salt;
$this->lock_timeout = $lock_timeout;
$this->session_lifetime = ini_get('session.gc_maxlifetime');
$this->session_lifetime = \ini_get('session.gc_maxlifetime');
}

/**
* @return void
*/
public function initialise()
{
session_set_save_handler($this, TRUE);
\session_set_save_handler($this, TRUE);
}

/**
Expand Down Expand Up @@ -158,7 +158,7 @@ public function write($id, $session_data)
'id' => $id,
'hash' => $this->calculateHash(),
'data' => $session_data,
'now' => date('Y-m-d H:i:s'),
'now' => \date('Y-m-d H:i:s'),
'user_agent' => $user_agent,
'ip' => $ip,
]
Expand All @@ -178,7 +178,7 @@ protected function calculateHash()

$hash .= $this->hash_salt;

return sha1($hash);
return \sha1($hash);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions test/phpunit-bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
\error_reporting(E_ALL);
\ini_set('display_errors', 1);

// Currently phpunit's default error handling doesn't properly catch warnings / errors from data providers
// https://github.com/sebastianbergmann/phpunit/issues/2449
set_error_handler(
\set_error_handler(
function ($severity, $message, $file, $line) {
throw new ErrorException($message, 0, $severity, $file, $line);
}
Expand Down
Loading

0 comments on commit 5c6ddbf

Please sign in to comment.