Skip to content

Commit 4e35a63

Browse files
authored
fix tests (#10)
* fix tests * add newline
1 parent 66e6ba5 commit 4e35a63

25 files changed

Lines changed: 144 additions & 121 deletions

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
vendor
22
composer.lock
3-
bin
3+
.php_cs.cache

.php_cs.dist

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
$finder = PhpCsFixer\Finder::create()
4+
->in(__DIR__)
5+
;
6+
7+
return PhpCsFixer\Config::create()
8+
->setRiskyAllowed(true)
9+
->setRules([
10+
'@Symfony' => true,
11+
'@Symfony:risky' => true,
12+
'array_syntax' => ['syntax' => 'short'],
13+
])
14+
->setFinder($finder)
15+
;

.travis.yml

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,33 @@
11
language: php
22

3-
php:
4-
- 5.5
3+
dist: xenial
4+
addons:
5+
apt:
6+
packages:
7+
- build-essential
8+
- cmake
9+
- libpcre3-dev
10+
- libgmp-dev
11+
- libssl-dev
512

6-
branches:
7-
only:
8-
- master
13+
php:
14+
- 7.1.19
915

1016
before_install:
11-
# PPA for libuv-dev
12-
- sudo apt-add-repository ppa:linuxjedi/ppa -y
13-
- sudo apt-get update
14-
- sudo apt-get install -y libuv-dev libssl-dev
15-
- cd /tmp && git clone https://github.com/datastax/php-driver.git && cd php-driver && git submodule update --init
16-
- cd ext && ./install.sh && cd "$TRAVIS_BUILD_DIR"
17-
- echo "extension=cassandra.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`
17+
# Cassandra Dependencies
18+
- wget http://downloads.datastax.com/cpp-driver/ubuntu/16.04/dependencies/libuv/v1.24.0/libuv1_1.24.0-1_amd64.deb && sudo dpkg -i libuv1_1.24.0-1_amd64.deb
19+
- wget http://downloads.datastax.com/cpp-driver/ubuntu/16.04/dependencies/libuv/v1.24.0/libuv1-dev_1.24.0-1_amd64.deb && sudo dpkg -i libuv1-dev_1.24.0-1_amd64.deb
20+
- wget http://downloads.datastax.com/cpp-driver/ubuntu/16.04/cassandra/v2.11.0/cassandra-cpp-driver_2.11.0-1_amd64.deb && sudo dpkg -i cassandra-cpp-driver_2.11.0-1_amd64.deb
21+
- wget http://downloads.datastax.com/cpp-driver/ubuntu/16.04/cassandra/v2.11.0/cassandra-cpp-driver-dev_2.11.0-1_amd64.deb && sudo dpkg -i cassandra-cpp-driver-dev_2.11.0-1_amd64.deb
22+
- pecl channel-update pecl.php.net && pecl install cassandra
23+
# PHP-cs-fixer
24+
- composer global require --dev 'friendsofphp/php-cs-fixer'
25+
- export PATH="$PATH:$HOME/.config/composer/vendor/bin:$HOME/.composer/vendor/bin"
1826

1927
install:
20-
- composer install -n --dev
28+
- composer install --prefer-dist -n -o
2129

2230
script:
23-
- bin/atoum
31+
- php-cs-fixer fix --dry-run --diff --no-ansi
32+
- vendor/bin/atoum
2433

Cassandra/Configurator.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static function buildCluster(Connection $connection)
2121
{
2222
$config = $connection->getConfig();
2323

24-
$consistency = constant('\Cassandra::CONSISTENCY_'.strtoupper($config['default_consistency']));
24+
$consistency = \constant('\Cassandra::CONSISTENCY_'.strtoupper($config['default_consistency']));
2525

2626
$cluster = new Builder();
2727
$cluster
@@ -36,17 +36,17 @@ public static function buildCluster(Connection $connection)
3636
->withCredentials($config['user'], $config['password'])
3737
->withProtocolVersion($config['protocol_version']);
3838

39-
if (isset($config['ssl']) && $config['ssl'] === true) {
39+
if (isset($config['ssl']) && true === $config['ssl']) {
4040
$ssl = new SSLOptionsBuilder();
4141
$sslOption = $ssl->withVerifyFlags(\Cassandra::VERIFY_NONE)->build();
4242
$cluster->withSSL($sslOption);
4343
}
4444

45-
if (array_key_exists('default_timeout', $config)) {
45+
if (\array_key_exists('default_timeout', $config)) {
4646
$cluster->withDefaultTimeout($config['default_timeout']);
4747
}
4848

49-
if ($config['load_balancing'] == 'round-robin') {
49+
if ('round-robin' == $config['load_balancing']) {
5050
$cluster->withRoundRobinLoadBalancingPolicy();
5151
} else {
5252
$dcOption = $config['dc_options'];

Cassandra/Connection.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public function getKeyspace()
126126
*/
127127
public function getSession()
128128
{
129-
if (is_null($this->session)) {
129+
if (null === $this->session) {
130130
$this->session = $this->cluster->connect($this->getKeyspace());
131131
}
132132

@@ -256,7 +256,7 @@ public function schema()
256256
*/
257257
protected function prepareResponse($response, CassandraEvent $event = null)
258258
{
259-
if (is_null($event)) {
259+
if (null === $event) {
260260
return $response;
261261
}
262262

@@ -280,7 +280,7 @@ protected function prepareResponse($response, CassandraEvent $event = null)
280280
*/
281281
protected function prepareEvent($command, array $args)
282282
{
283-
if (is_null($this->getEventDispatcher())) {
283+
if (null === $this->getEventDispatcher()) {
284284
return;
285285
}
286286

@@ -306,14 +306,14 @@ protected function send($command, array $arguments)
306306
$event = $this->prepareEvent($command, $arguments);
307307

308308
// The last arguments of call_user_func_array must not be null
309-
if (end($arguments) === null) {
309+
if (null === end($arguments)) {
310310
array_pop($arguments);
311311
}
312312

313313
$retry = $this->getMaxRetry();
314314
while ($retry >= 0) {
315315
try {
316-
$return = call_user_func_array([$this->getSession(), $command], $arguments);
316+
$return = \call_user_func_array([$this->getSession(), $command], $arguments);
317317

318318
// No exception, we can return the result
319319
$retry = -1;

Cassandra/ORM/EntityManager.php

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ public function getClassMetadata($className)
9090
/**
9191
* Gets the repository for an entity class.
9292
*
93-
* @param string $entityName The name of the entity.
93+
* @param string $entityName the name of the entity
9494
*
95-
* @return \CassandraBundle\Cassandra\ORM\EntityRepository The repository class.
95+
* @return \CassandraBundle\Cassandra\ORM\EntityRepository the repository class
9696
*/
9797
public function getRepository($entityName)
9898
{
@@ -102,12 +102,12 @@ public function getRepository($entityName)
102102
/**
103103
* Insert $entity to cassandra.
104104
*
105-
* @param object $entity
105+
* @param object $entity
106106
* @param Options $options |null
107107
*/
108108
public function insert($entity, Options $options = null)
109109
{
110-
$metadata = $this->getClassMetadata(get_class($entity));
110+
$metadata = $this->getClassMetadata(\get_class($entity));
111111
$tableName = $metadata->table['name'];
112112
$values = $this->readColumn($entity, $metadata);
113113
$columns = array_keys($values);
@@ -130,10 +130,12 @@ public function insert($entity, Options $options = null)
130130
}
131131

132132
/**
133-
* add options to statement
133+
* add options to statement.
134+
*
134135
* @param $statement
135136
* @param ClassMetadata $metadata
136-
* @param Options|null $options
137+
* @param Options|null $options
138+
*
137139
* @return string
138140
*/
139141
private function decorateInsertStatement($statement, ClassMetadata $metadata, Options $options = null)
@@ -144,17 +146,18 @@ private function decorateInsertStatement($statement, ClassMetadata $metadata, Op
144146
$statement .= ' IF NOT EXISTS ';
145147
}
146148
if (!empty($options) && !empty($options->getTtl())) {
147-
$statement .= ' USING TTL ' . $options->getTtl();
149+
$statement .= ' USING TTL '.$options->getTtl();
148150
} elseif (!empty($metadata->table['defaultTtl'])) {
149-
$statement .= ' USING TTL ' . $metadata->table['defaultTtl'];
151+
$statement .= ' USING TTL '.$metadata->table['defaultTtl'];
150152
}
153+
151154
return $statement;
152155
}
153156

154157
/**
155158
* Update $entity to cassandra.
156159
*
157-
* @param object $entity
160+
* @param object $entity
158161
* @param Options|null $options
159162
*
160163
* @deprecated update method will be deprecated since version 1.3 and will be removed in 1.5
@@ -171,7 +174,7 @@ public function update($entity, Options $options = null)
171174
*/
172175
public function delete($entity)
173176
{
174-
$metadata = $this->getClassMetadata(get_class($entity));
177+
$metadata = $this->getClassMetadata(\get_class($entity));
175178
$tableName = $metadata->table['name'];
176179

177180
$statement = sprintf(
@@ -191,12 +194,12 @@ public function delete($entity)
191194
*/
192195
public function flush($async = true)
193196
{
194-
if (count($this->statements)) {
197+
if (\count($this->statements)) {
195198
$this->logger->debug('CASSANDRA: BEGIN');
196199
$batch = new BatchStatement(\Cassandra::BATCH_LOGGED);
197200

198201
foreach ($this->statements as $statement) {
199-
$this->logger->debug('CASSANDRA: ' . $statement[self::STATEMENT] . ' => ' . json_encode($statement[self::ARGUMENTS]));
202+
$this->logger->debug('CASSANDRA: '.$statement[self::STATEMENT].' => '.json_encode($statement[self::ARGUMENTS]));
200203
$batch->add($this->prepare($statement[self::STATEMENT]), $statement[self::ARGUMENTS]);
201204
}
202205

@@ -220,9 +223,9 @@ public function flush($async = true)
220223
private function readColumn($entity, $metadata)
221224
{
222225
foreach ($metadata->fieldMappings as $field) {
223-
$getterMethod = 'get' . ucfirst($field['fieldName']);
226+
$getterMethod = 'get'.ucfirst($field['fieldName']);
224227
if (null !== $entity->{$getterMethod}()) {
225-
if($this->isCassandraType($entity->{$getterMethod}())) {
228+
if ($this->isCassandraType($entity->{$getterMethod}())) {
226229
$values[$field['columnName']] = $entity->{$getterMethod}();
227230
} else {
228231
$values[$field['columnName']] = $this->encodeColumnType($field['type'], $entity->{$getterMethod}());
@@ -242,20 +245,21 @@ private function readColumn($entity, $metadata)
242245
*/
243246
private function isCassandraType($obj)
244247
{
245-
$classNames = array('\Cassandra\Collection', '\Cassandra\Custom', '\Cassandra\Map', '\Cassandra\Scalar', '\Cassandra\Set', '\Cassandra\Tuple', '\Cassandra\UserType');
248+
$classNames = ['\Cassandra\Collection', '\Cassandra\Custom', '\Cassandra\Map', '\Cassandra\Scalar', '\Cassandra\Set', '\Cassandra\Tuple', '\Cassandra\UserType'];
246249
foreach ($classNames as $className) {
247250
if (is_a($obj, $className)) {
248251
return true;
249252
}
250253
}
254+
251255
return false;
252256
}
253257

254258
/**
255259
* Return $value with appropriate $type.
256260
*
257261
* @param string $type
258-
* @param mixed $value
262+
* @param mixed $value
259263
*
260264
* @return mixed
261265
*/
@@ -297,28 +301,28 @@ private function encodeColumnType($type, $value = null)
297301

298302
private function decodeColumnType($columnValue)
299303
{
300-
if ($columnValue === null) {
304+
if (null === $columnValue) {
301305
return $columnValue;
302306
}
303307

304308
try {
305-
if (is_bool($columnValue)) {
309+
if (\is_bool($columnValue)) {
306310
return $columnValue;
307311
}
308312
// Cassandra\Timestamp class
309-
if ($columnValue instanceOf \Cassandra\Timestamp) {
313+
if ($columnValue instanceof \Cassandra\Timestamp) {
310314
return $columnValue->time();
311315
}
312316
// Cassandra\Date class
313-
if ($columnValue instanceOf \Cassandra\Date) {
317+
if ($columnValue instanceof \Cassandra\Date) {
314318
return $columnValue->seconds();
315319
}
316320
// Cassandra\Time class
317-
if ($columnValue instanceOf \Cassandra\Time) {
321+
if ($columnValue instanceof \Cassandra\Time) {
318322
return $columnValue->seconds();
319323
}
320324
// Cassandra\Map class
321-
if ($columnValue instanceOf \Cassandra\Map) {
325+
if ($columnValue instanceof \Cassandra\Map) {
322326
$decodedKeys = [];
323327
foreach ($columnValue->keys() as $key) {
324328
$decodedKeys[] = $this->decodeColumnType($key);
@@ -331,7 +335,7 @@ private function decodeColumnType($columnValue)
331335
return array_combine($decodedKeys, $decodedValues);
332336
}
333337
// Cassandra\Set class
334-
if ($columnValue instanceOf \Cassandra\Set) {
338+
if ($columnValue instanceof \Cassandra\Set) {
335339
$decodedValues = [];
336340
foreach ($columnValue->values() as $value) {
337341
$decodedValues[] = $this->decodeColumnType($value);
@@ -340,7 +344,7 @@ private function decodeColumnType($columnValue)
340344
return $decodedValues;
341345
}
342346

343-
return (string)$columnValue;
347+
return (string) $columnValue;
344348
} catch (\Exception $e) {
345349
return $columnValue->values();
346350
}
@@ -361,10 +365,10 @@ public function cleanRow($cassandraRow)
361365
/**
362366
* Finds an Entity by its identifier.
363367
*
364-
* @param ClassMetadata $metadata The metadata of the entity to find.
365-
* @param mixed $id The identity of the entity to find.
368+
* @param ClassMetadata $metadata the metadata of the entity to find
369+
* @param mixed $id the identity of the entity to find
366370
*
367-
* @return object|null The entity instance or NULL if the entity can not be found.
371+
* @return object|null the entity instance or NULL if the entity can not be found
368372
*/
369373
public function find(ClassMetadata $metadata, $id)
370374
{
@@ -374,7 +378,7 @@ public function find(ClassMetadata $metadata, $id)
374378
try {
375379
$query->addParameter($id, 'uuid');
376380
} catch (\Cassandra\Exception\InvalidArgumentException $e) {
377-
$this->logger->error('CASSANDRA: ' . $e->getMessage());
381+
$this->logger->error('CASSANDRA: '.$e->getMessage());
378382

379383
return;
380384
}
@@ -386,11 +390,11 @@ public function find(ClassMetadata $metadata, $id)
386390
}
387391

388392
/**
389-
* Finds all entities
393+
* Finds all entities.
390394
*
391-
* @param ClassMetadata $metadata The metadata of the entity to find.
395+
* @param ClassMetadata $metadata the metadata of the entity to find
392396
*
393-
* @return ArrayCollection The array of entity instance or empty array if the entity can not be found.
397+
* @return ArrayCollection the array of entity instance or empty array if the entity can not be found
394398
*/
395399
public function findAll(ClassMetadata $metadata)
396400
{

Cassandra/ORM/EntityRepository.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ class EntityRepository
3434
/**
3535
* Initializes a new <tt>EntityRepository</tt>.
3636
*
37-
* @param EntityManager $em The EntityManager to use.
38-
* @param Mapping\ClassMetadata $class The class descriptor.
37+
* @param EntityManager $em the EntityManager to use
38+
* @param Mapping\ClassMetadata $class the class descriptor
3939
*/
4040
public function __construct($em, Mapping\ClassMetadata $class)
4141
{

Cassandra/ORM/Mapping/ClassMetadata.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class ClassMetadata
3737
*
3838
* @var array
3939
*/
40-
public $fieldMappings = array();
40+
public $fieldMappings = [];
4141

4242
/**
4343
* READ-ONLY: An array of field names. Used to look up field names from column names.
@@ -46,7 +46,7 @@ class ClassMetadata
4646
*
4747
* @var array
4848
*/
49-
public $fieldNames = array();
49+
public $fieldNames = [];
5050

5151
/**
5252
* READ-ONLY: The primary table definition. The definition is an array with the
@@ -63,7 +63,7 @@ class ClassMetadata
6363
/**
6464
* Creates a string representation of this instance.
6565
*
66-
* @return string The string representation of this instance.
66+
* @return string the string representation of this instance
6767
*
6868
* @todo Construct meaningful string representation.
6969
*/

0 commit comments

Comments
 (0)