richthegeek / phpsass

A compiler for SASS/SCSS written in PHP, brought up to date (approx 3.2) from a fork of PHamlP: http://code.google.com/p/phamlp/
http://phpsass.com/
382 stars 83 forks source link

compile warning messages on SassMediaNode.php #188

Open joejoseph00 opened 8 years ago

joejoseph00 commented 8 years ago

Compiling our scss gives us this message repeated for many of our @media during compile of .scss : `Undefined offset: 1 in SassMediaNode->__construct() (line 55 of core/sites/all/libraries/phpsass/tree/SassMediaNode.php).

Based on our .scss, we have @media used about 10 times. `

I debugged by writing to a text file the key variables involved at the line 55 and a few lines up before line 55 of phpsass/tree/SassMediaNode.php.

cat /www/debug2.txt

token->source=@media(max-width:374px)
self::MEDIA=1
matches[self::MEDIA]=
token->source=@media(max-width:420px)
self::MEDIA=1
matches[self::MEDIA]=
token->source=@media(max-width:461px)
self::MEDIA=1
matches[self::MEDIA]=
token->source=@media(max-width:480px)
self::MEDIA=1
matches[self::MEDIA]=
token->source=@media(max-width:540px)
self::MEDIA=1
matches[self::MEDIA]=
token->source=@media(max-width:767px)
self::MEDIA=1
matches[self::MEDIA]=
token->source=@media(min-width:768px) and (max-width:991px)
self::MEDIA=1
matches[self::MEDIA]=
token->source=@media(min-width:768px)
self::MEDIA=1
matches[self::MEDIA]=
token->source=@media(min-width:992px) and (max-width:1199px)
self::MEDIA=1
matches[self::MEDIA]=
token->source=@media(min-width:1200px)
self::MEDIA=1
matches[self::MEDIA]=
token->source=@media(max-width:1024px)
self::MEDIA=1
matches[self::MEDIA]=

Here is the useful debug code that was used to generate the above message.

diff --git a/tree/SassMediaNode.php b/tree/SassMediaNode.php
index 616f389..5b3006e 100644
--- a/tree/SassMediaNode.php
+++ b/tree/SassMediaNode.php
@@ -52,6 +52,18 @@ class SassMediaNode extends SassNode

     preg_match(self::MATCH, $token->source, $matches);
     $this->token = $token;
+
+if (!isset($matches[self::MEDIA])) {
+  $file = 'debug2.txt';
+  // Open the file to get existing content
+  $current = file_get_contents($file);
+  // Append a new person to the file
+  $current .= 'token->source=' . $token->source . "\n";
+  $current .= 'self::MEDIA=' . self::MEDIA . "\n";
+  $current .= 'matches[self::MEDIA]=' . $matches[self::MEDIA] . "\n";
+  // Write the contents back to the file
+  file_put_contents($file, $current);
+}
     $this->media = $matches[self::MEDIA];
   }
joejoseph00 commented 8 years ago

I modified the debug code slightly and retested:

Here's the output:

cat /www/debug2.txt

token->source=@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none)
self::MEDIA=1
matches[self::MEDIA]=media
token->source=@media only screen and (max-width : 320px)
self::MEDIA=1
matches[self::MEDIA]=media
token->source=@media(max-width:374px)
self::MEDIA=1
matches[self::MEDIA]=
token->source=@media (max-width:420px)
self::MEDIA=1
matches[self::MEDIA]=media
token->source=@media(max-width:461px)
self::MEDIA=1
matches[self::MEDIA]=
token->source=@media(max-width:480px)
self::MEDIA=1
matches[self::MEDIA]=
token->source=@media(max-width:540px)
self::MEDIA=1
matches[self::MEDIA]=
token->source=@media(max-width:767px)
self::MEDIA=1
matches[self::MEDIA]=
token->source=@media(min-width:768px) and (max-width:991px)
self::MEDIA=1
matches[self::MEDIA]=
token->source=@media(min-width:768px)
self::MEDIA=1
matches[self::MEDIA]=
token->source=@media(min-width:992px) and (max-width:1199px)
self::MEDIA=1
matches[self::MEDIA]=
token->source=@media only screen and (min-width : 992px)
self::MEDIA=1
matches[self::MEDIA]=media
token->source=@media(min-width:1200px)
self::MEDIA=1
matches[self::MEDIA]=
token->source=@media(max-width:1024px)
self::MEDIA=1
matches[self::MEDIA]=

here's the debug code used:

diff --git a/tree/SassMediaNode.php b/tree/SassMediaNode.php
index 616f389..89195c9 100644
--- a/tree/SassMediaNode.php
+++ b/tree/SassMediaNode.php
@@ -52,6 +52,18 @@ class SassMediaNode extends SassNode

     preg_match(self::MATCH, $token->source, $matches);
     $this->token = $token;
+
+//if (!isset($matches[self::MEDIA])) {
+  $file = 'debug2.txt';
+  // Open the file to get existing content
+  $current = file_get_contents($file);
+  // Append a new person to the file
+  $current .= 'token->source=' . $token->source . "\n";
+  $current .= 'self::MEDIA=' . self::MEDIA . "\n";
+  $current .= 'matches[self::MEDIA]=' . $matches[self::MEDIA] . "\n";
+  // Write the contents back to the file
+  file_put_contents($file, $current);
+//}
     $this->media = $matches[self::MEDIA];
   }
joejoseph00 commented 8 years ago

had a look at the regex, seems to not like this: @media(max-width:1234px)

joejoseph00 commented 8 years ago

possible hints for solution: https://www.drupal.org/node/1777712 and followup here:

https://www.drupal.org/node/2696329#comment-11745676

GDaw commented 7 years ago

Replacing @media (... with @media screen and (... has reduced the number of these notices that we see.