mirror of
https://github.com/chillerlan/php-qrcode.git
synced 2026-08-24 21:57:55 +00:00
🚿
This commit is contained in:
+2
-3
@@ -56,9 +56,6 @@ final class QRData{
|
||||
|
||||
/**
|
||||
* QRData constructor.
|
||||
*
|
||||
* @param \chillerlan\Settings\SettingsContainerInterface $options
|
||||
* @param \chillerlan\QRCode\Data\QRDataModeInterface[]|null $dataSegments
|
||||
*/
|
||||
public function __construct(SettingsContainerInterface $options, array $dataSegments = []){
|
||||
$this->options = $options;
|
||||
@@ -73,6 +70,8 @@ final class QRData{
|
||||
* Sets the data string (internally called by the constructor)
|
||||
*
|
||||
* Subsequent calls will overwrite the current state - use the QRCode::add*Segement() method instead
|
||||
*
|
||||
* @param \chillerlan\QRCode\Data\QRDataModeInterface[] $dataSegments
|
||||
*/
|
||||
public function setData(array $dataSegments):self{
|
||||
$this->dataSegments = $dataSegments;
|
||||
|
||||
+6
-7
@@ -166,8 +166,6 @@ class QRCode{
|
||||
/**
|
||||
* A collection of one or more data segments of [classname, data] to write
|
||||
*
|
||||
* @see \chillerlan\QRCode\Data\QRDataModeInterface
|
||||
*
|
||||
* @var \chillerlan\QRCode\Data\QRDataModeInterface[]
|
||||
*/
|
||||
protected array $dataSegments = [];
|
||||
@@ -179,8 +177,6 @@ class QRCode{
|
||||
|
||||
/**
|
||||
* QRCode constructor.
|
||||
*
|
||||
* Sets the options instance
|
||||
*/
|
||||
public function __construct(SettingsContainerInterface $options = null){
|
||||
$this->setOptions($options ?? new QROptions);
|
||||
@@ -347,6 +343,8 @@ class QRCode{
|
||||
|
||||
/**
|
||||
* Clears the data segments array
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function clearSegments():self{
|
||||
$this->dataSegments = [];
|
||||
@@ -439,9 +437,10 @@ class QRCode{
|
||||
// convert the string to the given charset
|
||||
if($eciCharsetName !== null){
|
||||
$data = mb_convert_encoding($data, $eciCharsetName, mb_internal_encoding());
|
||||
// add ECI designator
|
||||
$this->addSegment(new ECI($eciCharset->getID()));
|
||||
$this->addSegment(new Byte($data));
|
||||
$this
|
||||
->addEciDesignator($eciCharset->getID())
|
||||
->addByteSegment($data)
|
||||
;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -24,14 +24,12 @@ use function str_repeat;
|
||||
*/
|
||||
abstract class DataInterfaceTestAbstract extends TestCase{
|
||||
|
||||
protected ReflectionClass $reflection;
|
||||
protected QRData $QRData;
|
||||
protected string $FQN;
|
||||
protected string $testdata;
|
||||
protected QRData $QRData;
|
||||
protected string $FQN;
|
||||
protected string $testdata;
|
||||
|
||||
protected function setUp():void{
|
||||
$this->QRData = new QRData(new QROptions);
|
||||
$this->reflection = new ReflectionClass($this->QRData);
|
||||
$this->QRData = new QRData(new QROptions);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,7 +76,8 @@ abstract class DataInterfaceTestAbstract extends TestCase{
|
||||
public function testGetMinimumVersion():void{
|
||||
$this->QRData->setData([new $this->FQN($this->testdata)]);
|
||||
|
||||
$getMinimumVersion = $this->reflection->getMethod('getMinimumVersion');
|
||||
$reflection = new ReflectionClass(QRData::class);
|
||||
$getMinimumVersion = $reflection->getMethod('getMinimumVersion');
|
||||
$getMinimumVersion->setAccessible(true);
|
||||
/** @var \chillerlan\QRCode\Common\Version $version */
|
||||
$version = $getMinimumVersion->invoke($this->QRData);
|
||||
@@ -133,10 +132,10 @@ abstract class DataInterfaceTestAbstract extends TestCase{
|
||||
// get the filled bitbuffer
|
||||
$bitBuffer = $this->QRData->getBitBuffer();
|
||||
// read the first 4 bits
|
||||
$this::assertTrue($bitBuffer->read(4) === $datamodeInterface->getDataMode());
|
||||
$this::assertSame($datamodeInterface->getDataMode(), $bitBuffer->read(4));
|
||||
// hanzi mode starts with a subset indicator
|
||||
if($datamodeInterface instanceof Hanzi){
|
||||
$this::assertTrue($bitBuffer->read(4) === Hanzi::GB2312_SUBSET);
|
||||
$this::assertSame(Hanzi::GB2312_SUBSET, $bitBuffer->read(4));
|
||||
}
|
||||
// decode the data
|
||||
/** @noinspection PhpUndefinedMethodInspection */
|
||||
@@ -144,7 +143,7 @@ abstract class DataInterfaceTestAbstract extends TestCase{
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if an exception is thrown when the data exceeds the maximum version while auto detecting
|
||||
* Tests if an exception is thrown when the data exceeds the maximum version while auto-detecting
|
||||
*/
|
||||
public function testGetMinimumVersionException():void{
|
||||
$this->expectException(QRCodeDataException::class);
|
||||
|
||||
Reference in New Issue
Block a user