Skip to content
This repository was archived by the owner on Jan 10, 2023. It is now read-only.
Closed
Prev Previous commit
Next Next commit
cs fixes
  • Loading branch information
maglnet committed Jun 21, 2014
commit 9be0c58d5e0c0e0284c240bb919e935b4a05e1f2
18 changes: 10 additions & 8 deletions src/Detector/Adapter/HashStorage/HashStorageFactory.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* phpcpd
*
Expand Down Expand Up @@ -75,12 +76,13 @@ public static function createStorageAdapter($className = null)

return new $className();
}

/**
*
* @return string the configured default adapter to use
*/
public static function getDefaultAdapter(){
return self::$defaultAdapter;
}

/**
*
* @return string the configured default adapter to use
*/
public static function getDefaultAdapter()
{
return self::$defaultAdapter;
}
}
2 changes: 2 additions & 0 deletions src/Detector/Adapter/HashStorage/HashStorageInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* phpcpd
*
Expand Down Expand Up @@ -55,6 +56,7 @@
*/
interface HashStorageInterface
{

public function has($hash);

public function set($hash, $value);
Expand Down
1 change: 1 addition & 0 deletions src/Detector/Adapter/HashStorage/Memory.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* phpcpd
*
Expand Down
19 changes: 10 additions & 9 deletions src/Detector/Adapter/HashStorage/SQLite.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* phpcpd
*
Expand Down Expand Up @@ -72,17 +73,16 @@ public function __construct(array $options = null)
if (!extension_loaded('pdo_sqlite')) {
throw new \Exception('php module "pdo_sqlite" is not loaded');
}
if($options && isset($options['buffer_size'])){

if ($options && isset($options['buffer_size'])) {
$this->bufferSize = (int) $options['buffer_size'];
}

// prepare sqlite database
$this->dbFile = tempnam(sys_get_temp_dir(), 'phpcpd.sqlite.');
$this->db = new \PDO('sqlite:' . $this->dbFile);
$this->db->exec(self::$CREATE_SQL);
$this->insertStatement = $this->db->prepare(self::$INSERT_SQL);

}

public function __destruct()
Expand Down Expand Up @@ -136,8 +136,8 @@ private function flushBuffer()
$this->db->beginTransaction();

foreach ($this->hashBuffer as $hash => $value) {
$hash_md5 = md5($hash);
$value_serialized = serialize($value);
$hash_md5 = md5($hash);
$value_serialized = serialize($value);
$this->insertStatement->bindParam(':hash', $hash_md5);
$this->insertStatement->bindParam(':value', $value_serialized);
$this->insertStatement->execute();
Expand All @@ -147,7 +147,8 @@ private function flushBuffer()
$this->db->commit();
}

public function getDBFilename(){
return $this->dbFile;
}
public function getDBFilename()
{
return $this->dbFile;
}
}