7a8fece21b0410de0d04b3f16e100c1ddc375f37 — Emil Oppeln-Bronikowski 3 months ago 667a455
Sweet merciful Jesus
1 files changed, 31 insertions(+), 8 deletions(-)

M __main__.py
M __main__.py => __main__.py +31 -8
@@ 26,24 26,35 @@ return False
  
  def has_use(line: str) -> bool:
-     if 'use' in line:
+     if 'use ' in line:
+         return True
+     if 'namespace ' in line:
          return True
      return False
  
  def extract_namespace(line: str) -> list:
  
+     by_spaces = line.split(" ")
+     for token in by_spaces:
+         if is_line_namespaced(token):
+             line = token
+             break
+ 
      elements = line[line.find("\\"):].split("\\")
      org_class_element = elements[-1:][0]
  
+     class_element = org_class_element
+ 
      if '::' in org_class_element:
          class_element = org_class_element.split('::')[0]
      else:
-         class_element = org_class_element
+         if '(' in org_class_element:
+             class_element = org_class_element.split('(')[0]
  
      elements[len(elements)-1] = class_element
  
-     return("\\".join(elements), org_class_element)
- 
+     print(elements, class_element, org_class_element)
+     return("\\".join(elements), class_element)
  
  def test_bool_call(func, param):
      if func(param):


@@ 57,19 68,31 @@ use += "use {};\n".format(c)
      return use
  
- 
  def main(file_path: str):
  
      namespaces = []
      with open(file_path, 'r') as f:
          for line in f.readlines():
-             if is_line_namespaced(line) and not is_slash_quoted(line) and has_use(line):
+             if is_line_namespaced(line) and not is_slash_quoted(line) and not has_use(line):
                  path, class_element = extract_namespace(line)
                  namespaces.append(path)
-                 print("{}\n{}".format(line, line.replace(path[:-1], "").replace("\\", "")))
+                 # print("{}\n{}".format(line, line.replace(path[:-1], "").replace("\\", "")))
+                 print("Yes ", line)
+                 print(path, class_element)
+                 input()
+ 
+             else:
+                 print("No ", line)
  
-     print(set(namespaces))
+     #print(set(namespaces))
      print(return_import_statements(set(namespaces)))
  
  if len(sys.argv) == 2:
      main(sys.argv[1])
+ 
+ t = "throw new \\App\\Exceptions\\VoucherDoesNotExists($serial);"
+ t2 = "function derp(\\App\\User $user) {"
+ print(test_bool_call(is_line_namespaced, t2))
+ print(test_bool_call(is_slash_quoted, t2))
+ print(test_bool_call(has_use, t2))
+ print(extract_namespace(t2))