Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
gam6itko committed Sep 30, 2020
2 parents b1dc3c5 + e1037af commit ee09d62
Show file tree
Hide file tree
Showing 101 changed files with 4,257 additions and 1,406 deletions.
22 changes: 0 additions & 22 deletions .php_cs

This file was deleted.

30 changes: 30 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

$rules = [
'@Symfony' => true,
'binary_operator_spaces' => [
'operators' => [
'=>' => 'align',
],
],
'blank_line_after_opening_tag' => false, // <?php declare(strict_types=1);
'single_quote' => true,
'yoda_style' => true,
'no_empty_phpdoc' => true,
'no_extra_blank_lines' => true,
'phpdoc_align' => true,
'phpdoc_trim' => true,
'increment_style' => ['style' => 'post'],
'no_superfluous_phpdoc_tags' => true,
'declare_strict_types' => true,
];

$finder = PhpCsFixer\Finder::create()
->in('src')
->in('tests');

return PhpCsFixer\Config::create()
->setFinder($finder)
->setRiskyAllowed(true)
->setRules($rules)
->setUsingCache(true);
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# CHANGELOG

## 1.3

- all setters return $this.
- getters for type `D` (Date) now returns date string in 'Ymd' format instead of timestamp.
- `VisualFoxproRecord::getDateTime` returns object of `\DateTimeInterface` instead of timestamp.

### deprecated

- setters like getType are deprecated. Use set('name', $value) method instead.
- getters like getType are deprecated. Use get('name') method instead.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,5 @@ Useful links
[Xbase File Format Description](http://www.manmrk.net/tutorials/database/xbase/)

[File Structure for dBASE 7](http://www.dbase.com/KnowledgeBase/int/db7_file_fmt.htm)

[DBF AND DBT/FPT FILE STRUCTURE](http://www.independent-software.com/dbase-dbf-dbt-file-format.html)
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
}
],
"require": {
"php": ">=7.1"
"php": ">=7.1",
"ext-iconv": "*"
},
"autoload": {
"psr-4": {
Expand All @@ -34,7 +35,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "1.2.x-dev"
"dev-master": "1.3.x-dev"
}
}
}
3 changes: 2 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.3/phpunit.xsd"
bootstrap="vendor/autoload.php"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
verbose="true">
Expand Down
61 changes: 61 additions & 0 deletions src/XBase/BlocksMerger.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php declare(strict_types=1);

namespace XBase;

/**
* Used to store and merge memo deleted area.
*
* @author Alexander Strizhak <gam6itko@gmail.com>
*
* @internal
*/
final class BlocksMerger
{
private $blocksToDelete = [];

public function add(int $pointer, int $length): self
{
$this->blocksToDelete[] = [$pointer, $length];

return $this;
}

public function clear(): void
{
$this->blocksToDelete = [];
}

public function get(): array
{
return $this->squeeze();
}

private function squeeze(): array
{
$pointers = array_column($this->blocksToDelete, 0);
array_multisort($pointers, SORT_ASC, $this->blocksToDelete);

$result = [];
$i = null;
$nextPointer = null;
foreach ($this->blocksToDelete as $arr) {
[$pointer, $length] = $arr;
if ($pointer < $nextPointer) {
continue;
} elseif ($nextPointer === $pointer) {
$result[$i] += $length;
} else {
$i = $pointer;
$result[$pointer] = $length;
}
$nextPointer = $pointer + $length;
}

return $result;
}

public function isEmpty(): bool
{
return empty($this->blocksToDelete);
}
}
54 changes: 23 additions & 31 deletions src/XBase/Column/AbstractColumn.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);

namespace XBase\Column;

Expand All @@ -7,7 +7,7 @@ abstract class AbstractColumn implements ColumnInterface
/** @var string */
protected $name;

/** @var string */
/** @var string|null */
protected $rawName;

/** @var string */
Expand All @@ -16,18 +16,20 @@ abstract class AbstractColumn implements ColumnInterface
/** @var int */
protected $length;

/** @var int */
/** @var int|null */
protected $decimalCount;

/**@var int Field address within record. */
/** @var int Field address within record. */
protected $memAddress;

/** @var int|null */
protected $workAreaID;

/** @var bool */
protected $setFields;
/** @var bool|null */
protected $setFields = false;

protected $indexed;
/** @var bool|null */
protected $indexed = false;

/** @var int|null Data starts from index */
protected $bytePos;
Expand All @@ -43,60 +45,47 @@ public function getMemAddress()
return $this->memAddress;
}

/**
* @return bool|string
*/
public function getName()
public function getName(): string
{
return $this->name;
}

public function isSetFields()
public function isSetFields(): ?bool
{
return $this->setFields;
}

public function getType()
public function getType(): string
{
return $this->type;
}

public function getWorkAreaID()
public function getWorkAreaID(): ?int
{
return $this->workAreaID;
}

public function getDecimalCount()
public function getDecimalCount(): ?int
{
return $this->decimalCount;
}

/**
* @return bool
*/
public function isIndexed()
public function isIndexed(): ?bool
{
return $this->indexed;
}

/**
* @return int
*/
public function getLength()
public function getLength(): int
{
return $this->length;
}

public function getColIndex()
public function getColIndex(): int
{
return $this->colIndex;
}

/**
* @return int
* @deprecated use getMemAddress
*/
public function getBytePos()
public function getBytePos(): int
{
return $this->bytePos;
}
Expand All @@ -109,12 +98,15 @@ public function __toString()
/**
* @return string
*/
public function getRawName()
public function getRawName(): ?string
{
return $this->rawName;
}

public function getDataLength()
/**
* @deprecated since 1.3 and will be delete in 2.0. Use getLength()
*/
public function getDataLength(): int
{
return $this->length;
}
Expand Down
4 changes: 2 additions & 2 deletions src/XBase/Column/ColumnFactory.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php
<?php declare(strict_types=1);

namespace XBase\Column;

use XBase\Enum\TableType;

class ColumnFactory
{
public static function getClass(string $version): string
public static function getClass(int $version): string
{
switch ($version) {
case TableType::DBASE_7_MEMO:
Expand Down
7 changes: 4 additions & 3 deletions src/XBase/Column/ColumnInterface.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
<?php declare(strict_types=1);

namespace XBase\Column;

use XBase\Record;
use XBase\Stream\StreamWrapper;

interface ColumnInterface
{
Expand All @@ -13,6 +13,8 @@ public static function getHeaderLength(): int;
*/
public static function create(string $memoryChunk, int $colIndex, ?int $bytePos = null);

public function toBinaryString(StreamWrapper $fp): void;

public function getDecimalCount();

/**
Expand Down Expand Up @@ -43,7 +45,6 @@ public function getWorkAreaID();

/**
* @return int
* @deprecated use getMemAddress
*/
public function getBytePos();

Expand Down
Loading

0 comments on commit ee09d62

Please sign in to comment.