Skip to content

Commit

Permalink
Merge pull request #3890 from oleibman/reorgsamples
Browse files Browse the repository at this point in the history
Reorganize Samples
  • Loading branch information
oleibman authored Feb 4, 2024
2 parents ec5e664 + 17845d8 commit c2f9af6
Show file tree
Hide file tree
Showing 225 changed files with 29 additions and 26 deletions.
3 changes: 3 additions & 0 deletions Header.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

require __DIR__ . '/samples/Header.php';
10 changes: 0 additions & 10 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
parameters:
ignoreErrors:
-
message: "#^Parameter \\#1 \\$formula of method PhpOffice\\\\PhpSpreadsheet\\\\Cell\\\\DataValidation\\:\\:setFormula1\\(\\) expects string, int given\\.$#"
count: 1
path: samples/Basic/15_Datavalidation.php

-
message: "#^Parameter \\#1 \\$formula of method PhpOffice\\\\PhpSpreadsheet\\\\Cell\\\\DataValidation\\:\\:setFormula2\\(\\) expects string, int given\\.$#"
count: 1
path: samples/Basic/15_Datavalidation.php

-
message: "#^Strict comparison using \\=\\=\\= between mixed and null will always evaluate to false\\.$#"
count: 1
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
$validation->setError('Only numbers between 10 and 20 are allowed!');
$validation->setPromptTitle('Allowed input');
$validation->setPrompt('Only numbers between 10 and 20 are allowed.');
$validation->setFormula1(10);
$validation->setFormula2(20);
$validation->setFormula1('10');
$validation->setFormula2('20');

$validation = $spreadsheet->getActiveSheet()->getCell('B5')->getDataValidation();
$validation->setType(DataValidation::TYPE_LIST);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
}

$categories = ConvertUOM::getConversionCategories();
$defaultCategory = $_POST['category'] ?? $categories[0];
$units = [];
foreach ($categories as $category) {
$categoryUnits = ConvertUOM::getConversionCategoryUnitDetails($category)[$category];
Expand Down Expand Up @@ -48,7 +49,7 @@
<label for="fromUnit" class="col-sm-2 col-form-label">From Unit</label>
<div class="col-sm-10">
<select name="fromUnit" class="form-select">
<?php foreach ($units[$_POST['category']] as $fromUnitCode => $fromUnitName) {
<?php foreach ($units[$defaultCategory] as $fromUnitCode => $fromUnitName) {
echo "<option value=\"{$fromUnitCode}\" " . ((isset($_POST['fromUnit']) && $_POST['fromUnit'] === $fromUnitCode) ? 'selected' : '') . ">{$fromUnitName}</option>", PHP_EOL;
} ?>
</select>
Expand All @@ -58,27 +59,33 @@
<label for="toUnit" class="col-sm-2 col-form-label">To Unit</label>
<div class="col-sm-10">
<select name="toUnit" class="form-select">
<?php foreach ($units[$_POST['category']] as $toUnitCode => $toUnitName) {
<?php foreach ($units[$defaultCategory] as $toUnitCode => $toUnitName) {
echo "<option value=\"{$toUnitCode}\" " . ((isset($_POST['toUnit']) && $_POST['toUnit'] === $toUnitCode) ? 'selected' : '') . ">{$toUnitName}</option>", PHP_EOL;
} ?>
</select>
</div>
</div>
<div class="mb-3 row">
<div class="col-sm-10">
<input class="btn btn-primary" name="submit" type="submit" value="Convert"><br />
<input class="btn btn-primary" name="submitx" type="submit" value="Convert"><br />
</div>
</div>
</form>

<?php
/** If the user has submitted the form, then we need to calculate the value and display the result */
if (isset($_POST['submit'])) {
if (isset($_POST['quantity'], $_POST['fromUnit'], $_POST['toUnit'])) {
$quantity = $_POST['quantity'];
$fromUnit = $_POST['fromUnit'];
$toUnit = $_POST['toUnit'];
/** @var float|string */
$result = ConvertUOM::CONVERT($quantity, $fromUnit, $toUnit);
if (isset($units[$_POST['category']][$fromUnit], $units[$_POST['category']][$toUnit])) {
/** @var float|string */
$result = ConvertUOM::CONVERT($quantity, $fromUnit, $toUnit);

echo "{$quantity} {$units[$_POST['category']][$fromUnit]} is {$result} {$units[$_POST['category']][$toUnit]}", PHP_EOL;
echo "{$quantity} {$units[$_POST['category']][$fromUnit]} is {$result} {$units[$_POST['category']][$toUnit]}", PHP_EOL;
} else {
echo 'Please enter quantity and select From Unit and To Unit', PHP_EOL;
}
} else {
echo 'Please enter quantity and select From Unit and To Unit', PHP_EOL;
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added samples/Reader2/sampleData/example1.xls
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions samples/bootstrap/css/phpspreadsheet.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ body {
.navbar {
margin-bottom: 20px;
}
.navbar + h1 {
margin-top: 70px;
}
.passed {
color: #339900;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/PhpSpreadsheetTests/IOFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,14 @@ public function testCreateInvalidReader(): void

public function testCreateReaderUnknownExtension(): void
{
$filename = 'samples/Reader/sampleData/example1.tsv';
$filename = 'samples/Reader2/sampleData/example1.tsv';
$reader = IOFactory::createReaderForFile($filename);
self::assertEquals('PhpOffice\\PhpSpreadsheet\\Reader\\Csv', $reader::class);
}

public function testCreateReaderCsvExtension(): void
{
$filename = 'samples/Reader/sampleData/example1.csv';
$filename = 'samples/Reader2/sampleData/example1.csv';
$reader = IOFactory::createReaderForFile($filename);
self::assertEquals('PhpOffice\\PhpSpreadsheet\\Reader\\Csv', $reader::class);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/PhpSpreadsheetTests/Reader/Csv/CsvContiguousTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class CsvContiguousTest extends TestCase
{
private string $inputFileName = 'samples/Reader/sampleData/example2.csv';
private string $inputFileName = 'samples/Reader2/sampleData/example2.csv';

public function testContiguous(): void
{
Expand Down
8 changes: 4 additions & 4 deletions tests/PhpSpreadsheetTests/Reader/Csv/CsvTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ public static function providerDelimiterDetection(): array
'Number of items with weight <= 50kg',
],
[
'samples/Reader/sampleData/example1.csv',
'samples/Reader2/sampleData/example1.csv',
',',
'I4',
'100%',
],
[
'samples/Reader/sampleData/example2.csv',
'samples/Reader2/sampleData/example2.csv',
',',
'D8',
-58.373161,
Expand Down Expand Up @@ -107,8 +107,8 @@ public static function providerCanLoad(): array
[true, 'tests/data/Reader/CSV/csv_without_extension'],
[true, 'tests/data/Reader/HTML/csv_with_angle_bracket.csv'],
[true, 'tests/data/Reader/CSV/empty.csv'],
[true, 'samples/Reader/sampleData/example1.csv'],
[true, 'samples/Reader/sampleData/example2.csv'],
[true, 'samples/Reader2/sampleData/example1.csv'],
[true, 'samples/Reader2/sampleData/example2.csv'],
];
}

Expand Down

0 comments on commit c2f9af6

Please sign in to comment.