Skip to content

Commit ee09d62

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents b1dc3c5 + e1037af commit ee09d62

File tree

101 files changed

+4257
-1406
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+4257
-1406
lines changed

.php_cs

Lines changed: 0 additions & 22 deletions
This file was deleted.

.php_cs.dist

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
$rules = [
4+
'@Symfony' => true,
5+
'binary_operator_spaces' => [
6+
'operators' => [
7+
'=>' => 'align',
8+
],
9+
],
10+
'blank_line_after_opening_tag' => false, // <?php declare(strict_types=1);
11+
'single_quote' => true,
12+
'yoda_style' => true,
13+
'no_empty_phpdoc' => true,
14+
'no_extra_blank_lines' => true,
15+
'phpdoc_align' => true,
16+
'phpdoc_trim' => true,
17+
'increment_style' => ['style' => 'post'],
18+
'no_superfluous_phpdoc_tags' => true,
19+
'declare_strict_types' => true,
20+
];
21+
22+
$finder = PhpCsFixer\Finder::create()
23+
->in('src')
24+
->in('tests');
25+
26+
return PhpCsFixer\Config::create()
27+
->setFinder($finder)
28+
->setRiskyAllowed(true)
29+
->setRules($rules)
30+
->setUsingCache(true);

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# CHANGELOG
2+
3+
## 1.3
4+
5+
- all setters return $this.
6+
- getters for type `D` (Date) now returns date string in 'Ymd' format instead of timestamp.
7+
- `VisualFoxproRecord::getDateTime` returns object of `\DateTimeInterface` instead of timestamp.
8+
9+
### deprecated
10+
11+
- setters like getType are deprecated. Use set('name', $value) method instead.
12+
- getters like getType are deprecated. Use get('name') method instead.

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,5 @@ Useful links
121121
[Xbase File Format Description](http://www.manmrk.net/tutorials/database/xbase/)
122122

123123
[File Structure for dBASE 7](http://www.dbase.com/KnowledgeBase/int/db7_file_fmt.htm)
124+
125+
[DBF AND DBT/FPT FILE STRUCTURE](http://www.independent-software.com/dbase-dbf-dbt-file-format.html)

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
}
1717
],
1818
"require": {
19-
"php": ">=7.1"
19+
"php": ">=7.1",
20+
"ext-iconv": "*"
2021
},
2122
"autoload": {
2223
"psr-4": {
@@ -34,7 +35,7 @@
3435
},
3536
"extra": {
3637
"branch-alias": {
37-
"dev-master": "1.2.x-dev"
38+
"dev-master": "1.3.x-dev"
3839
}
3940
}
4041
}

phpunit.xml.dist

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit bootstrap="vendor/autoload.php"
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.3/phpunit.xsd"
3+
bootstrap="vendor/autoload.php"
34
beStrictAboutOutputDuringTests="true"
45
beStrictAboutTodoAnnotatedTests="true"
56
verbose="true">

src/XBase/BlocksMerger.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace XBase;
4+
5+
/**
6+
* Used to store and merge memo deleted area.
7+
*
8+
* @author Alexander Strizhak <gam6itko@gmail.com>
9+
*
10+
* @internal
11+
*/
12+
final class BlocksMerger
13+
{
14+
private $blocksToDelete = [];
15+
16+
public function add(int $pointer, int $length): self
17+
{
18+
$this->blocksToDelete[] = [$pointer, $length];
19+
20+
return $this;
21+
}
22+
23+
public function clear(): void
24+
{
25+
$this->blocksToDelete = [];
26+
}
27+
28+
public function get(): array
29+
{
30+
return $this->squeeze();
31+
}
32+
33+
private function squeeze(): array
34+
{
35+
$pointers = array_column($this->blocksToDelete, 0);
36+
array_multisort($pointers, SORT_ASC, $this->blocksToDelete);
37+
38+
$result = [];
39+
$i = null;
40+
$nextPointer = null;
41+
foreach ($this->blocksToDelete as $arr) {
42+
[$pointer, $length] = $arr;
43+
if ($pointer < $nextPointer) {
44+
continue;
45+
} elseif ($nextPointer === $pointer) {
46+
$result[$i] += $length;
47+
} else {
48+
$i = $pointer;
49+
$result[$pointer] = $length;
50+
}
51+
$nextPointer = $pointer + $length;
52+
}
53+
54+
return $result;
55+
}
56+
57+
public function isEmpty(): bool
58+
{
59+
return empty($this->blocksToDelete);
60+
}
61+
}

src/XBase/Column/AbstractColumn.php

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
namespace XBase\Column;
44

@@ -7,7 +7,7 @@ abstract class AbstractColumn implements ColumnInterface
77
/** @var string */
88
protected $name;
99

10-
/** @var string */
10+
/** @var string|null */
1111
protected $rawName;
1212

1313
/** @var string */
@@ -16,18 +16,20 @@ abstract class AbstractColumn implements ColumnInterface
1616
/** @var int */
1717
protected $length;
1818

19-
/** @var int */
19+
/** @var int|null */
2020
protected $decimalCount;
2121

22-
/**@var int Field address within record. */
22+
/** @var int Field address within record. */
2323
protected $memAddress;
2424

25+
/** @var int|null */
2526
protected $workAreaID;
2627

27-
/** @var bool */
28-
protected $setFields;
28+
/** @var bool|null */
29+
protected $setFields = false;
2930

30-
protected $indexed;
31+
/** @var bool|null */
32+
protected $indexed = false;
3133

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

46-
/**
47-
* @return bool|string
48-
*/
49-
public function getName()
48+
public function getName(): string
5049
{
5150
return $this->name;
5251
}
5352

54-
public function isSetFields()
53+
public function isSetFields(): ?bool
5554
{
5655
return $this->setFields;
5756
}
5857

59-
public function getType()
58+
public function getType(): string
6059
{
6160
return $this->type;
6261
}
6362

64-
public function getWorkAreaID()
63+
public function getWorkAreaID(): ?int
6564
{
6665
return $this->workAreaID;
6766
}
6867

69-
public function getDecimalCount()
68+
public function getDecimalCount(): ?int
7069
{
7170
return $this->decimalCount;
7271
}
7372

74-
/**
75-
* @return bool
76-
*/
77-
public function isIndexed()
73+
public function isIndexed(): ?bool
7874
{
7975
return $this->indexed;
8076
}
8177

82-
/**
83-
* @return int
84-
*/
85-
public function getLength()
78+
public function getLength(): int
8679
{
8780
return $this->length;
8881
}
8982

90-
public function getColIndex()
83+
public function getColIndex(): int
9184
{
9285
return $this->colIndex;
9386
}
9487

95-
/**
96-
* @return int
97-
* @deprecated use getMemAddress
98-
*/
99-
public function getBytePos()
88+
public function getBytePos(): int
10089
{
10190
return $this->bytePos;
10291
}
@@ -109,12 +98,15 @@ public function __toString()
10998
/**
11099
* @return string
111100
*/
112-
public function getRawName()
101+
public function getRawName(): ?string
113102
{
114103
return $this->rawName;
115104
}
116105

117-
public function getDataLength()
106+
/**
107+
* @deprecated since 1.3 and will be delete in 2.0. Use getLength()
108+
*/
109+
public function getDataLength(): int
118110
{
119111
return $this->length;
120112
}

src/XBase/Column/ColumnFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
namespace XBase\Column;
44

55
use XBase\Enum\TableType;
66

77
class ColumnFactory
88
{
9-
public static function getClass(string $version): string
9+
public static function getClass(int $version): string
1010
{
1111
switch ($version) {
1212
case TableType::DBASE_7_MEMO:

src/XBase/Column/ColumnInterface.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
namespace XBase\Column;
44

5-
use XBase\Record;
5+
use XBase\Stream\StreamWrapper;
66

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

16+
public function toBinaryString(StreamWrapper $fp): void;
17+
1618
public function getDecimalCount();
1719

1820
/**
@@ -43,7 +45,6 @@ public function getWorkAreaID();
4345

4446
/**
4547
* @return int
46-
* @deprecated use getMemAddress
4748
*/
4849
public function getBytePos();
4950

0 commit comments

Comments
 (0)