Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default Editorconfig #182

Merged
merged 1 commit into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# http://EditorConfig.org

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.json]
indent_style = tab

[*.md]
indent_size = 4
indent_style = tab

[*.php]
indent_style = tab

[*.xml]
indent_style = tab

[*.yml]
indent_size = 2
indent_style = space
2 changes: 1 addition & 1 deletion src/CssXPathException.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

use RuntimeException;

class CssXPathException extends RuntimeException {}
class CssXPathException extends RuntimeException {}
2 changes: 1 addition & 1 deletion src/NotYetImplementedException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
namespace Gt\CssXPath;

class NotYetImplementedException extends CssXPathException {}
class NotYetImplementedException extends CssXPathException {}
18 changes: 9 additions & 9 deletions src/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected function convertSingleSelector(string $css):string {
$thread = array_values($thread);

$xpath = [$this->prefix];
$hasElement = false;
$hasElement = false;
foreach($thread as $threadKey => $currentThreadItem) {
$next = isset($thread[$threadKey + 1])
? $thread[$threadKey + 1]
Expand All @@ -71,7 +71,7 @@ protected function convertSingleSelector(string $css):string {
case "star":
case "element":
$xpath []= $currentThreadItem['content'];
$hasElement = true;
$hasElement = true;
break;

case "pseudo":
Expand Down Expand Up @@ -161,7 +161,7 @@ protected function convertSingleSelector(string $css):string {

case "child":
array_push($xpath, "/");
$hasElement = false;
$hasElement = false;
break;

case "id":
Expand All @@ -170,31 +170,31 @@ protected function convertSingleSelector(string $css):string {
($hasElement ? '' : '*')
. "[@id='{$currentThreadItem['content']}']"
);
$hasElement = true;
$hasElement = true;
break;

case "class":
// https://devhints.io/xpath#class-check
array_push(
$xpath,
($hasElement ? '' : '*')
($hasElement ? '' : '*')
. "[contains(concat(' ',normalize-space(@class),' '),' {$currentThreadItem['content']} ')]"
);
$hasElement = true;
$hasElement = true;
break;

case "sibling":
array_push(
$xpath,
"/following-sibling::*[1]/self::"
);
$hasElement = false;
$hasElement = false;
break;

case "attribute":
if(!$hasElement) {
array_push($xpath, "*");
$hasElement = true;
$hasElement = true;
}

/** @var null|array<int, array<string, string>> $detail */
Expand Down Expand Up @@ -263,7 +263,7 @@ protected function convertSingleSelector(string $css):string {

case "descendant":
array_push($xpath, "//");
$hasElement = false;
$hasElement = false;
break;
}
}
Expand Down
38 changes: 19 additions & 19 deletions test/phpunit/Helper/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ class Helper {
<span>Site logo</span>
</a>
</h1>

<nav class="c-menu main-selection">
<input type="checkbox" id="toggle-menu" />
<label for="toggle-menu">
<span>Menu</span>
</label>

<ul>
<li>
<a href="/">Home</a>
Expand All @@ -58,7 +58,7 @@ class Helper {

<main>
<p>I'm a paragraph, but I'm not part of the article.</p>

<article>
<header>
<h1>
Expand Down Expand Up @@ -111,24 +111,24 @@ class Helper {
<label>
<span>From:</span>
<select name="from">
<option>0</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>0</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
</label>

<label>
<span>To:</span>
<select name="to">
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>10</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>10</option>
</select>
</label>
</form>
Expand All @@ -138,7 +138,7 @@ class Helper {
<!doctype html>
<form method="post">
<p>Please select and of the following:</p>

<label>
<input type="checkbox" name="choice[]" value="1" />
<span>Choice 1</span>
Expand All @@ -151,12 +151,12 @@ class Helper {
<input type="checkbox" name="choice[]" value="3" />
<span>Choice 3</span>
</label>

<button>Submit</button>
</form>
HTML;

const HTML_SELECTORS = <<<HTML
const HTML_SELECTORS = <<<HTML
<!doctype html>
<html>
<head>
Expand Down