<commit_before>###*
 * PHP files namespace management
###

module.exports =
  ###*
   * Add the good namespace to the given file
   * @param {TextEditor} editor
  ###
  createNamespace: (editor) ->
    proxy = require './php-proxy.coffee'

    composer    = proxy.composer()
    autoloaders = []

    # Get elements from composer.json
    for psr, autoload of composer.autoload
        for namespace, src of autoload
            autoloaders[src] = namespace

    # Get the current path of the file
    path = editor.getPath()
    for directory in atom.project.getDirectories()
        if path.indexOf(directory.path) == 0
            path = path.substr(directory.path.length+1)
            break

    # Get the root namespace
    namespace = null
    for src, name of autoloaders
        if path.indexOf(src) == 0
            path = path.substr(src.length)
            namespace = name
            break

    # No namespace found ? Let's leave
    if namespace == null
        return

    # If the path starts with "/", we remove it
    if path.indexOf("/") == 0
        path = path.substr(1)

    elements = path.split('/')

    # Build the namespace
    index = 1
    for element in elements
        if element == "" or index == elements.length
            continue

        namespace = if namespace == "" then element else namespace + "\\" + element
        index++

    text = editor.getText()
    index = 0

    # Search for the good place to write the namespace
    lines = text.split('\n')
    for line in lines
      line = line.trim()

      # If we found class keyword, we are not in namespace space, so return
      if line.indexOf('class ') != -1 || line.indexOf('use ') != -1
        editor.setTextInBufferRange([[index,0], [index, 0]], "namespace #{namespace};\n\n")
        return

      if line.indexOf('namespace ') == 0
        editor.setTextInBufferRange([[index,0], [index+1, 0]], "namespace #{namespace};\n")
        return

      index += 1

    return null<commit_msg>Change the namespace conditional index<commit_after>###*
 * PHP files namespace management
###

module.exports =
  ###*
   * Add the good namespace to the given file
   * @param {TextEditor} editor
  ###
  createNamespace: (editor) ->
    proxy = require './php-proxy.coffee'

    composer    = proxy.composer()
    autoloaders = []

    # Get elements from composer.json
    for psr, autoload of composer.autoload
        for namespace, src of autoload
            autoloaders[src] = namespace

    # Get the current path of the file
    path = editor.getPath()
    for directory in atom.project.getDirectories()
        if path.indexOf(directory.path) == 0
            path = path.substr(directory.path.length+1)
            break

    # Get the root namespace
    namespace = null
    for src, name of autoloaders
        if path.indexOf(src) == 0
            path = path.substr(src.length)
            namespace = name
            break

    # No namespace found ? Let's leave
    if namespace == null
        return

    # If the path starts with "/", we remove it
    if path.indexOf("/") == 0
        path = path.substr(1)

    elements = path.split('/')

    # Build the namespace
    index = 1
    for element in elements
        if element == "" or index == elements.length
            continue

        namespace = if namespace == "" then element else namespace + "\\" + element
        index++

    text = editor.getText()
    index = 0

    # Search for the good place to write the namespace
    lines = text.split('\n')
    for line in lines
      line = line.trim()

      # If we found class keyword, we are not in namespace space, so return
      if line.indexOf('namespace ') == 0
        editor.setTextInBufferRange([[index,0], [index+1, 0]], "namespace #{namespace};\n")
        return
      else if line.trim() != "" and line.trim().indexOf("<?") != 0
        editor.setTextInBufferRange([[index,0], [index, 0]], "namespace #{namespace};\n\n")
        return

      index += 1

    editor.setTextInBufferRange([[2 ,0], [2, 0]], "namespace #{namespace};\n\n")
{'fraction_non_alphanumeric': 0.11744471744471745, 'fraction_numerical': 0.0085995085995086, 'mean_word_length': 2.233518665607625, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '335439', 'n_tokens_mistral': 1169, 'n_tokens_neox': 1111, 'n_words': 378}