|
| 1 | +#!/usr/bin/env php |
| 2 | +<?php |
| 3 | + |
| 4 | +require __DIR__ . '/../vendor/autoload.php'; |
| 5 | + |
| 6 | +function saveDataset(string $className, array $referential): void |
| 7 | +{ |
| 8 | + $datasetClass = new ReflectionClass($className); |
| 9 | + $datasetFile = $datasetClass->getFileName(); |
| 10 | + |
| 11 | + $referentialString = var_export($referential, true); |
| 12 | + $referentialString = str_replace('array (', '[', $referentialString); |
| 13 | + $referentialString = str_replace(')', ']', $referentialString); |
| 14 | + |
| 15 | + $datasetFileContent = file_get_contents($datasetFile); |
| 16 | + $datasetFileContent = preg_replace( |
| 17 | + '/public static array \$referential = \[.*?\];/s', |
| 18 | + 'public static array $referential = ' . $referentialString . ';', |
| 19 | + $datasetFileContent |
| 20 | + ); |
| 21 | + |
| 22 | + file_put_contents($datasetFile, $datasetFileContent); |
| 23 | +} |
| 24 | + |
| 25 | +$cssPropertiesFile = __DIR__ . '/../tests/fixtures/css-properties.json'; |
| 26 | +$cssProperties = json_decode(file_get_contents($cssPropertiesFile), true); |
| 27 | + |
| 28 | +$standardsProperties = []; |
| 29 | +$nonStandardsProperties = []; |
| 30 | + |
| 31 | +foreach ($cssProperties as $propertyName => $property) { |
| 32 | + $isStandard = $property['standard'] ?? false; |
| 33 | + if ($isStandard) { |
| 34 | + $standardsProperties[$propertyName] = true; |
| 35 | + } else { |
| 36 | + $nonStandardsProperties[$propertyName] = true; |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +// Add missing non-standard properties |
| 41 | +$missingNonStandardsProperties = [ |
| 42 | + '-webkit-overflow-scrolling', |
| 43 | + '-webkit-margin-end', |
| 44 | + '-moz-osx-font-smoothing', |
| 45 | +]; |
| 46 | +foreach ($missingNonStandardsProperties as $propertyName) { |
| 47 | + if (isset($standardsProperties[$propertyName]) || isset($nonStandardsProperties[$propertyName])) { |
| 48 | + throw new Exception("Property $propertyName already exists in either standards or non-standards properties."); |
| 49 | + } |
| 50 | + $nonStandardsProperties[$propertyName] = true; |
| 51 | +} |
| 52 | + |
| 53 | +ksort($standardsProperties); |
| 54 | +ksort($nonStandardsProperties); |
| 55 | +saveDataset(CssLint\Referential\StandardPropertiesReferential::class, $standardsProperties); |
| 56 | +saveDataset(CssLint\Referential\NonStandardPropertiesReferential::class, $nonStandardsProperties); |
0 commit comments